Skip to content

Commit

Permalink
Adds group assignment (tab) to edit user view [#933 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed Feb 26, 2013
1 parent a37779b commit a8a3115
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 28 deletions.
2 changes: 1 addition & 1 deletion framework/modules/administration/menus/admin.php
Expand Up @@ -340,7 +340,7 @@
'classname' => 'egroup',
),
array(
'text' => gt('Profile Definitions'),
'text' => gt('User Profile Extensions'),
'url' => makeLink(array(
'controller' => 'users',
'action' => 'manage_extensions'
Expand Down
40 changes: 40 additions & 0 deletions framework/modules/users/controllers/usersController.php
Expand Up @@ -124,6 +124,27 @@ public function edituser() {
'extensions' => $active_extensions,
"userkey" => expSession::get("userkey")
));

if ($user->isAdmin()) {
$page = new expPaginator(array(
'model' => 'group',
'where' => 1,
'limit' => (isset($this->config['limit']) && $this->config['limit'] != '') ? $this->config['limit'] : 10,
'order' => empty($this->config['order']) ? 'name' : $this->config['order'],
'page' => (isset($this->params['page']) ? $this->params['page'] : 1),
'columns' => array(
gt('Name') => 'name',
gt('Description') => 'description',
),
'controller' => $this->baseclassname,
'action' => $this->params['action'],
));

assign_to_template(array(
'groups' => $page,
'mygroups' => $u->getGroupMemberships(),
));
}
}

public function update() {
Expand Down Expand Up @@ -185,6 +206,25 @@ public function update() {
}
}

// update group membership assignment
if (!empty($this->params['member'])) {
$old_groups = $db->selectObjects('groupmembership', 'member_id=' . $u->id);
// $db->delete('groupmembership', 'member_id=' . $u->id); // start from scratch
$memb = new stdClass();
$memb->member_id = $u->id;
foreach ($this->params['member'] as $grp) {
$memb->group_id = $grp;
$memb->is_admin = false;
foreach ($old_groups as $oldgroup) {
if ($oldgroup->group_id == $grp) {
if ($oldgroup->is_admin) $memb->is_admin = true; // retain group admin setting
}
}
$db->insertObject($memb, 'groupmembership');
}
if ($u->id == $user->id) expPermissions::triggerRefresh();
}

// if this is a new account then we will check to see if we need to send
// a welcome message or admin notification of new accounts.
if (empty($id)) {
Expand Down
10 changes: 2 additions & 8 deletions framework/modules/users/views/users/edit_group.tpl
Expand Up @@ -15,18 +15,12 @@

<div class="module module action">
<h1>{'Create User Group'|gettext}</h1>
<p>
{'If you check the \'Default?\' checkbox, user accounts created after this group is saved will be added to it.'|gettext}&#160;&#160;
{'This will not retro-actively add existing users to this group.'|gettext}
</p>

{form action=update_group}
{control type="hidden" name="id" value=$record->id}
{control type="text" name="name" label="Name"|gettext value=$record->name}
{control type="textarea" name="description" label="Description"|gettext value=$record->description}
{*{control type="text" name="redirect" label="Login Landing Page"|gettext value=$record->redirect}*}
{control type="dropdown" name="redirect" label="Login Landing Page"|gettext includeblank="None"|gettext items=navigationController::levelDropdownControlArray(0,0,array(),false,'view',true) value=$record->redirect}
{control type="checkbox" name="inclusive" label="Default Group"|gettext:cat:'?' value=1 checked=$record->inclusive}
{control type="dropdown" name="redirect" label="Login Landing Page"|gettext includeblank="None"|gettext items=navigationController::levelDropdownControlArray(0,0,array(),false,'view',true) value=$record->redirect description='Redirect group members to a specific page when logging in'|gettext}
{control type="checkbox" name="inclusive" label="Is this a Default Group?"|gettext:cat:'?' value=1 checked=$record->inclusive description='Should new accounts be automatically assigned to this group?'|gettext}
{control type="buttongroup" submit="Submit"|gettext cancel="Cancel"|gettext}
{/form}
</div>
52 changes: 48 additions & 4 deletions framework/modules/users/views/users/edituser.tpl
Expand Up @@ -13,6 +13,10 @@
*
*}

{css unique="edit_user" corecss="tables"}

{/css}

<div id='edituser' class="module users edit">
{form action=update}
<div class="info-header">
Expand All @@ -28,8 +32,11 @@
<div id="edituser-tabs" class="yui-navset exp-skin-tabview hide">
<ul class="yui-nav">
<li class="selected"><a href="#tab1"><em>{"General"|gettext}</em></a></li>
{if !empty($groups->records)}
<li class="selected"><a href="#tab2"><em>{"Group Membership"|gettext}</em></a></li>
{/if}
{foreach from=$extensions item=extension}
<li><a href="#tab{$extension->id}"><em>{$extension->title}</em></a></li>
<li><a href="#tab{$extension->id+2}"><em>{$extension->title}</em></a></li>
{/foreach}
</ul>
<div class="yui-content">
Expand Down Expand Up @@ -69,10 +76,47 @@
{/if}
{/if}
</div>
{if !empty($groups->records)}
<div id="tab2">
{pagelinks paginate=$groups top=1}
<table class="exp-skin-table">
<thead>
<tr>
{$groups->header_columns}
<th>{'Member'|gettext}</th>
</tr>
</thead>
<tbody>
{foreach from=$groups->records item=group name=listings}
<tr class="{cycle values="odd,even"}">
<td>{$group->name}</td>
<td>{$group->description}</td>
<td>
{$checked = false}
{foreach from=$mygroups item=mygroup}
{if $mygroup->id == $group->id}
{$checked = true}
{/if}
{/foreach}
{if $edit_user->isAdmin()}
{control type=checkbox name='member[]' value=$group->id checked=$checked disabled=true}
{else}
{control type=checkbox name='member[]' value=$group->id checked=$checked}
{/if}
</td>
</tr>
{foreachelse}
<tr><td colspan="{$groups->columns|count}">{'No User Groups Available'|gettext}.</td></tr>
{/foreach}
</tbody>
</table>
{pagelinks paginate=$groups bottom=1}
</div>
{/if}
{foreach from=$extensions item=extension}
<div id="tab{$extension->id}" >
{include file="`$smarty.const.BASE`framework/modules/users/views/extensions/`$extension->classname`.tpl"}
</div>
<div id="tab{$extension->id+2}" >
{include file="`$smarty.const.BASE`framework/modules/users/views/extensions/`$extension->classname`.tpl"}
</div>
{/foreach}
</div>
</div>
Expand Down
30 changes: 15 additions & 15 deletions framework/modules/users/views/users/manage_groups.tpl
Expand Up @@ -42,22 +42,22 @@
</thead>
<tbody>
{foreach from=$page->records item=group name=listings}
<tr class="{cycle values="odd,even"}">
<td>{$group->name}</td>
<td>{$group->description}</td>
<td>{if $group->inclusive}<strong>{'Default'|gettext}</strong>{else}{'Normal'|gettext}{/if}</td>
<td>
{permissions}
<div class="item-actions">
{icon img="groupperms.png" controller=users action="manage_group_memberships" record=$group title="Add/Remove Members to Group"|gettext|cat:" "|cat:$group->name}
{icon img="edit.png" controller=users action=edit_group record=$group title="Edit this group"|gettext}
{icon img="delete.png" controller=users action=delete_group record=$group title="Delete this group"|gettext onclick="return confirm('"|cat:("Are you sure you want to delete this group?"|gettext)|cat:"');"}
</div>
{/permissions}
</td>
</tr>
<tr class="{cycle values="odd,even"}">
<td>{$group->name}</td>
<td>{$group->description}</td>
<td>{if $group->inclusive}<strong>{'Default'|gettext}</strong>{else}{'Normal'|gettext}{/if}</td>
<td>
{permissions}
<div class="item-actions">
{icon img="groupperms.png" controller=users action="manage_group_memberships" record=$group title="Add/Remove Members to Group"|gettext|cat:" "|cat:$group->name}
{icon img="edit.png" controller=users action=edit_group record=$group title="Edit this group"|gettext}
{icon img="delete.png" controller=users action=delete_group record=$group title="Delete this group"|gettext onclick="return confirm('"|cat:("Are you sure you want to delete this group?"|gettext)|cat:"');"}
</div>
{/permissions}
</td>
</tr>
{foreachelse}
<td colspan="{$page->columns|count}">{'No Data'|gettext}.</td>
<tr><td colspan="{$page->columns|count}">{'No User Groups Available'|gettext}.</td></tr>
{/foreach}
</tbody>
</table>
Expand Down

0 comments on commit a8a3115

Please sign in to comment.