Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zilla’s picture

i noticed the same thing - just wondering why it was removed. i'd also love to see it return (limit invitation by role, etc)

zilla’s picture

bump: any word from the maintainer on whether or not this feature is coming to the d7 version of invite?

ckng’s picture

Version: 7.x-4.0-beta1 » 7.x-4.x-dev
Component: Miscellaneous » Code
Issue summary: View changes
Status: Active » Postponed

Will get to it.

Tim Bozeman’s picture

Status: Postponed » Needs review
FileSize
6.63 KB

This patch ports the basic role limit from 7.2.

Tim Bozeman’s picture

With new line.

Tim Bozeman’s picture

Added remaining invites text to the form and changed a permission string so the role would apply.

ckng’s picture

Thanks Tim for the patch. I think I forget to mention would prefer this as a submodule, maybe invite_limit to make it more maintainable and user who don't need the functionality do not need to bother with it. Do you think that's doable with current code base?

Tim Bozeman’s picture

Heya ckng, I separated it into it's own submodule.

Tim Bozeman’s picture

I left off 2 functions in the shuffle.

Tim Bozeman’s picture

FileSize
6.98 KB
608 bytes

Changed the permission string from 'send invitations' to 'create any invite entities'.

ckng’s picture

Status: Needs review » Needs work
  1. +++ b/invite.module
    @@ -702,7 +702,7 @@ function invite_target_roles($invite, $account) {
    +  $roles = array_intersect($inviter->roles, user_roles(TRUE, 'create any invite entities'));
    

    Using 'create any invite entities' is no longer accurate, since now we have "create invite_type->type entity" permissions. But this is more to invite permission design which we will need to revisit.

  2. +++ b/modules/invite_limit/invite_limit.module
    @@ -0,0 +1,154 @@
    +    $form['role'][$rid]['invite_maxnum_' . $rid] = array(
    

    need to add uninstall to remove there variables.

  3. +++ b/modules/invite_limit/invite_limit.module
    @@ -0,0 +1,154 @@
    +      '#options' => array(
    +        5 => 5,
    +        10 => 10,
    +        15 => 15,
    +        20 => 20,
    +        25 => 25,
    +        50 => 50,
    +        100 => 100,
    +        500 => 500,
    +        1000 => 1000,
    +        INVITE_UNLIMITED => t('unlimited')
    +      ),
    

    IMHO, using select is very limiting where a textfield would be better.

  4. +++ b/modules/invite_limit/invite_limit.module
    @@ -0,0 +1,154 @@
    +      '#description' => t('Allows to limit the total number of invitations members of %role can send.', array('%role' => $role)),
    

    Add hint for unlimited (-1) when converted to use textfield.

  5. +++ b/modules/invite_limit/invite_limit.module
    @@ -0,0 +1,154 @@
    +    $data['subject'] = t('No more invites.');
    +    $data['content'] = t('You have no remaining invites left.');
    

    If these are configurable, that would be more usable. Including enable the block overriding.

Tim Bozeman’s picture

Thank you for reviewing ckng!

  1. Okay, lets circle back around to this one.
  2. I named spaced the variables a little better and added a hook_uninstall().
  3. Switched to a textfield.
  4. Added a hint in the description about the unlimited value.
  5. I made this text configurable and added an option to enable/disable the block if no invites remain.
Tim Bozeman’s picture

Status: Needs work » Needs review
Tim Bozeman’s picture

New line.

ckng’s picture

Any suggestion for (1)?

Hopefully find time to review this week.

Tim Bozeman’s picture

FileSize
9.53 KB
834 bytes

How about this?

ckng’s picture

I reorganized the invite limit block and shorten the variable names.

ckng’s picture

Status: Needs review » Needs work
+++ b/modules/invite_limit/invite_limit.module
@@ -0,0 +1,202 @@
+  $roles = user_roles(FALSE, 'create any invite entities');
+  if (count($roles) == 0) {
+    drupal_set_message(t('Please enable the <em>create any invite entities</em> permission for at least one role on the <a href="@url">permissions page</a>.', array('@url' => $permissions_url)), 'warning');
+  }
+  $target_roles = user_roles(TRUE);
+
+  // Role settings.
+  $form['invite_limit']['role'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Role settings'),
+    '#description' => t('To control which roles may send invitations visit the <a href="@url">permissions page</a>.', array('@url' => $permissions_url)),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#group' => 'additional_settings',
+  );
+
+  foreach ($roles as $rid => $role) {
+    $form['invite_limit']['role'][$rid] = array(
+      '#type' => 'fieldset',
+      '#title' => t('@role settings', array('@role' => drupal_ucfirst($role))),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+
+    $form['invite_limit']['role'][$rid]['invite_target_role_' . $rid] = array(
+      '#type' => 'select',
+      '#title' => t('Target role'),
+      '#default_value' => variable_get('invite_target_role_' . $rid, DRUPAL_AUTHENTICATED_RID),
+      '#options' => $target_roles,
+      '#description' => t('You may choose to add invited users to a role when they have been invited by a member of %role.', array('%role' => $role)),
+      '#required' => TRUE,
+    );
+
+    $form['invite_limit']['role'][$rid]['invite_limit_maxnum_' . $rid] = array(
+      '#type' => 'textfield',
+      '#title' => t('Invitation limit'),
+      '#default_value' => variable_get('invite_limit_maxnum_' . $rid, INVITE_LIMIT_UNLIMITED),
+      '#description' => t('Total number of invites %roles can send. Enter -1 for unlimited.', array('%role' => $role)),
+      '#required' => TRUE,
+    );
+  }
+}

For (1), I'm actually referring to this section of codes. Nonetheless, the other section you fixed is needed as well.

The current patch only cater for permission 'create any invite entities'. For current invite implementation, there should be ability to limit by the invite types. Hence, it should be limits by roles of each invite type, where 'create any invite entities' is the default. Make sense?

Tim Bozeman’s picture

Ah. I see what you mean. I'm just using roles.

Tim Bozeman’s picture

Issue summary: View changes
FileSize
14.12 KB
10.39 KB
40.45 KB

I haven't wired up the permission checking part yet, but I reworked the settings page.
Limits by invite type and role

Tim Bozeman’s picture

Issue summary: View changes
pendaco’s picture

Great work! Would love to see this in a new update.

@ Tim Bozeman
There's 1 small typo in your patch above; 'Defualt' instead of 'Default'

nithinkolekar’s picture

some observations
#1. permission pattern "Invite by e-mail create new invites" which fails with 'create ' . $invite->getBundle() . ' entity'

#2. default settings are applying although role specific is configured.(May be #1 is causing this)

#3. Please enable the create any invite entities permission for at least one role on the permission . It is like assigning all invites permission to a single role which make that user almost semi admin. It should be "Enable permission to at least one invite type"

Tim Bozeman’s picture

nithinkkolekar, thanks for looking at it. #17 is a working patch, but the permissions don't meet the design specs ckng is after. #20 makes an attempt to accommodate a more robust permissions scheme, but I haven't gotten further than simply placing the form elements yet.

Tim Bozeman’s picture

Status: Needs work » Needs review
FileSize
13.9 KB
10.07 KB

I wired up the invite limit type and role checking. What do you think ckng?

function invite_limit_get_limits($account, $invite_type) {
  if (!isset($account->roles)) {
    $account = user_load($account->uid);
  }
  $roles = $account->roles;
  $limit = INVITE_LIMIT_UNLIMITED;
  $invite_limits = variable_get('invite_limits', '-1');
  if (isset($invite_limits)) {
    // Check for role limit.
    if (!empty($invite_limits[$invite_type]['role'])) {
      $role_limit_check = '-1';
      foreach ($invite_limits[$invite_type]['role'] as $key => $role_limit) {
        if (array_key_exists($role_limit['target'], $roles)) {
          $role_limit_check = ($role_limit['max'] > $role_limit_check) ? $role_limit['max'] : $role_limit_check;
        }
      }
      $limit = $role_limit_check;
    }
    // Check for type limit.
    elseif (!empty($invite_limits[$invite_type]['default'])) {
      $limit = $invite_limits['enterprise']['default'];
    }
  }

  return $limit;
}
Tim Bozeman’s picture

Tidy things up a bit.

Tim Bozeman’s picture

FileSize
6.04 KB
Tim Bozeman’s picture

Doronro’s picture

subscribe

Donit’s picture

Currently, every user can view ANY invites from other users by simple URL hacks, even when just view/edit OWN is enabled. Does this patch solves this issue?

brockdray’s picture

So I'm not a developer, and applying patches is not really in my wheelhouse. Any chance this is going to be moved into the main module anytime soon? I would love to add this functionality to my site. Thanks!

royerd’s picture

I can't find the ability to limit invites in the 7x versions. Was that feature ever added?