I wanted to put all group members into a group specific "basic" role. It would then be one way to give each author posting to a group the possibility to give specific access controls to roles / users (over that node) with for example the "Node Access"-module. Very much like a group founder role, just for everyone in group. This role of course shouldn't be give to anyone side-wide.

The idea is pretty basic, and I was wondering if the same thing is already available via some other easy way - but I didn't find any. It's not a very big feature, so I went though the module's code (lot's of code in this module I must say!) and tested some things. After a few hours I got this feature working, mostly by copying the code under og_user_roles_nodeapi() insert-case, that gave all group creators optionally a group founder role.

I thought I'd share this, if other people need this. This one is not really an issue, but maybe Somebodyssysop or someone could comment if there's something wrong with the code. It's seems to be working fine for me, but I haven't tested it much.

I should learn to make patches to make this easier for everyone... but the other reason to post this is to ask if this code could maybe be included in some release of the module in future (without my comments of course)?

Heres the code. I added the needed admin options basicly by copying the group founder -settings.

	// ---- Modification
	// Added basic group role option for user roles
	// - bibo
	$form["og_user_roles_basicgrouprole"] = array(
      '#type' => 'fieldset',
      '#title' => t('Default Basic Group Role for all users in each group.'),
   	  '#description' => t('Allows you to select a group role to automatically assign to users who join a group on your site. The role is specific to the group(s) this user creates.  That is, the user will only have the privileges of the role in the group that he creates.'),
    );

    $form["og_user_roles_basicgrouprole"]["og_user_roles_assign_basicgrouprole"] = array(
      '#type' => 'checkbox',
      '#title' => t('Set default basic group (group limited) role for users who join groups?'),
      '#default_value' => variable_get("og_user_roles_assign_basicgrouprole", 0),
   	  '#description' => t('Do you wish to automatically assign <b>every user</b> to a group specific basic role that is limited to the group that he creates? This role can be be removed by the groups\' admins'),
    );
    $form["og_user_roles_basicgrouprole"]["og_user_roles_basicgrouprole_value"] = array(
      '#type' => 'select',
      '#title' => t('Role to use as a basic group role'),
      '#options' => $roles,
      '#default_value' => variable_get("og_user_roles_basicgrouprole_value", 0),
   	  '#description' => t('Select the role you wish to use as the "basic group role" for every groupmember.'),
    );
	//
	// --- end of modification

Then I checked another module (og_promote) to see where the user_insert case is happening (when a user is added to a group). In the code it's at the implementation of "hook_og" which means "og_user_roles_og()". I then just adjusted the beginning of the function like this:

function og_user_roles_og($op, $nid, $uid, $args = array()) {
    switch ($op) {
      case 'user insert':
		
		//----------
		// Adding every user to a basic group restricted role, that all users in the group should have.
		// I don't know a better way, so I'll do it like this. This is based on the creating of a founder role,
		// just that every user in the group should automagically get this role.
		// -Bibo
		if (variable_get("og_user_roles_assign_basicgrouprole", 0) == 1) {
			$rid = variable_get("og_user_roles_basicgrouprole_value", 0);
			og_user_roles_role_join($uid, $rid, $nid); // assign user to group role in that group
		}
		//--- end of modification 

Is this the correct way to do this, and if yes, can this feature be added to the module?

CommentFileSizeAuthor
#1 og_user_roles.module_0.txt46.07 KBbibo

Comments

bibo’s picture

StatusFileSize
new46.07 KB

As there's no patch, maybe uploading the latest version (1.1) with my changes is clearer than the code I posted. At least if you check it with WinMerge.

Oh, an unrelated note: I also changed one other thing, wrapped the "(unsubscribe)"-text with the function t() around line 349, for easy localization of the string. Using t("String to localize") is pretty important for people who need to localize all strings to some non-english language, like I do :).

somebodysysop’s picture

Funny. I was just thinking the other day that I should probably add this functionality as well.

As you've probably noticed, I actually like keeping in comments. As well as previous code. I think it helps people to understand what's going on. And, the more they understand, the more easily they can come up with great contributions like this.

Thanks bibo!

I'll get this committed soon.

bibo’s picture

Wow, that's great to hear :)

somebodysysop’s picture

Assigned: Unassigned » somebodysysop
Status: Active » Fixed

These modifications now committed to latest release. Thanks for the suggestions and code.

somebodysysop’s picture

Status: Fixed » Closed (fixed)