Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Setting to specify default membership type.

Aloittaja jstelly, helmikuu 17, 2007, 02:09:19 IP

« edellinen - seuraava »

jstelly

I've run into a problem with the way members are added to membergroups.  This is from the 1.1.1 release.

By default, when adding a member to a membergroup using the 'add' field at the bottom of a membergroup listing, the membership is added as 'auto' which tries to set the primary group if one isn't set.  The problem is that setting the primary group removes users from the "regular members" default group... so that "regular members" group loses a lot of it's usefulness.  I'd rather see adding a member to a group add it as an additional group and have a separate screen where I have to explicitly select a member's primary group if I want them to be something other than a regular member.

You can find some details in another thread I created about the problem/behavior I was seeing here but I'd suggest reading that after reading this post.

Getting down to the code:

When adding a member to a membergroup, the MembergroupMembers() method in ManageMembergroups.php calls addMembersToGroup() in the Subs-Members.php file like this:


// !!! Add $_POST['additional'] to templates!

// Do the updates...
require_once($sourcedir . '/Subs-Members.php');
addMembersToGroup($members, $_REQUEST['group'], isset($_POST['additional']) ? 'only_additional' : 'auto');


So I guess that this means a theme can modify the behavior of adding a member to a membergroup.  Is that correct?  I'm a developer by trade, and I have a couple concerns with allowing that, mainly that my administrators or moderators have to know that 'this theme adds membership as additional, while maybe this other one doesn't'.  In my mind, the default membership type should be a server setting, so I did the following:

Ran this SQL command

INSERT INTO smf_settings (variable, value) VALUE ('defaultMembershipType', 'only_additional')


Modified the MembergroupMembers() method in ManageMembergroups.php

// !!! Add $_POST['additional'] to templates!

$membershipType = 'auto';
if(isset($_POST['additional']))
{
$membershipType = 'only_additional';
}
else if(!empty($settings['defaultMembershipType']))
{
$membershipType = $settings['defaultMembershipType'];
}

// Do the updates...
require_once($sourcedir . '/Subs-Members.php');
addMembersToGroup($members, $_REQUEST['group'], $membershipType);


Note: I kept the check for a post variable to not break functionality in case not everyone thinks like I do, but I really don't feel like group membership type should be something a theme can change

Fix a syntax error in the addMembersToGroup() method in Subs-Members.php

Original code

// Do the actual updates.
if ($type == 'only_additional')
db_query("
UPDATE {$db_prefix}members
SET additionalGroups = IF(additionalGroups = '', '$group', CONCAT(additionalGroups, ',$group')))
WHERE ID_MEMBER IN (" . implode(', ', $members) . ")
AND ID_GROUP != $group
AND NOT FIND_IN_SET($group, additionalGroups)
LIMIT " . count($members), __FILE__, __LINE__);


Removed the extraneous ')'

SET additionalGroups = IF(additionalGroups = '', '$group', CONCAT(additionalGroups, ',$group'))


Any thoughts on getting this added to a future release?

codac

#1
I agree with this.
Intuitively a user should not be stripped of privileges when added to a new group, right? (if that group has a few grants, but no "deny" permissions)

If a new user is created and I add him/her to a group via: Admin panel -> Membergroups -> "GroupInQuestion" -> Add member, then that user leaves the group "Regular members", thereby loosing all privileges that are not explicitly given to the new group.

Like suggested above, I would prefer a specific option to "Change primary group", and the more general "Add to group" not changing the primary group. I think that would save many new administrators some head scratching (and possibly annoyance). :)

Thanks for a great forum!


Advertisement: