AU-Landing-Project / au_subgroups

Allows creation of groups within groups
6 stars 11 forks source link

Group-owner cannot create a Sub-Group if "groups" plugin setting "Who can create new groups" is set on "Administration" #15

Open oseg opened 8 years ago

oseg commented 8 years ago

Scenario: 1- In the Elgg Administration/Configure/Settings/Groups, set "Who can create new groups?" to "Administration" 2- As an admin create a group with the following settings: . Check: Subgroups: Enable Sub-Groups for this group? . Uncheck: Subgroups: Enable any member to create subgroups? (if no, only group admins will be able to create subgroups) 3- As an admin, change the group owner of this group to be a non admin user 4- Connect as the group owner and go to the group profile page 5- Click on the "Create a Sub-Group" button 6- Fill in the "Create a Sub-Group" page and click on the save button =>An error message is displayed: "You can not create a group. Only admins can."

issue reproduced on both elgg v1.12 and v2.2

This error message happens because of a groups setting check in the groups/edit action (groups plugin): elgg_get_plugin_setting('limited_groups', 'groups') == 'yes'

To fix the issue, overload the groups/edit action with this kind of code for instance:

 $group_guid = (int)get_input('group_guid');
 $is_new_group = $group_guid == 0;

$is_subgroup = false;
if ($is_new_group 
    && elgg_is_active_plugin('au_subgroups') 
    && (get_input('au_subgroups_parent_guid', false) !== false)) {
        $is_subgroup = true;
}

 if ($is_new_group
    && (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes')
    && !$is_subgroup
    && !$user->isAdmin()) {
    register_error(elgg_echo("groups:cantcreate"));
    forward(REFERER);
 }
dragonjon commented 7 years ago

Hi @oseg The same problem for me, but your solution don't work for my or is needed more changes. I test in 2.1.1 and 2.2.0 with the las version os subgroups 2.1.1 Some help?? @beck24

oseg commented 7 years ago

Hi dragonjon, Be careful, some 3rd party plugins (like group_tools for instance) overwrite the groups/edit action. In these cases, you need to patch the actions/groups/edit.php file in the 3rd party plugin directory (group_tools for instance).

dragonjon commented 7 years ago

Thanks @oseg for the advise I test in some days in the group tools plugins, is installed in my dev system too. Good work Thanks Jon