Skip to Content.
Sympa Menu

comanage-dev - [comanage-dev] r502 - in registry/trunk/app: Controller Lib Model View/CoGroups

Subject: COmanage Developers List

List archive

[comanage-dev] r502 - in registry/trunk/app: Controller Lib Model View/CoGroups


Chronological Thread 
  • From:
  • To:
  • Subject: [comanage-dev] r502 - in registry/trunk/app: Controller Lib Model View/CoGroups
  • Date: Fri, 19 Apr 2013 16:42:56 -0400
  • Authentication-results: sfpop-ironport04.merit.edu; dkim=neutral (message not signed) header.i=none

Author: benno
Date: 2013-04-19 16:42:56 -0400 (Fri, 19 Apr 2013)
New Revision: 502

Modified:
registry/trunk/app/Controller/CoGroupMembersController.php
registry/trunk/app/Controller/CoGroupsController.php
registry/trunk/app/Lib/enum.php
registry/trunk/app/Lib/lang.php
registry/trunk/app/Model/CoGroupMember.php
registry/trunk/app/View/CoGroups/index.ctp
Log:
Overhaul group membership selection for CO-598 (and CO-74)

Modified: registry/trunk/app/Controller/CoGroupMembersController.php
===================================================================
--- registry/trunk/app/Controller/CoGroupMembersController.php 2013-04-16
03:51:08 UTC (rev 501)
+++ registry/trunk/app/Controller/CoGroupMembersController.php 2013-04-19
20:42:56 UTC (rev 502)
@@ -284,6 +284,9 @@
// This is for REST
$p['index'] = ($this->restful && ($roles['cmadmin'] ||
$roles['coadmin']));

+ // Update accepts a CO Person's worth of potential group memberships and
performs the appropriate updates
+ $p['update'] = ($roles['cmadmin'] || $roles['comember']);
+
// Select from a list of potential members to add?
$p['select'] = ($roles['cmadmin'] || $managed);

@@ -388,4 +391,34 @@

$this->set('co_group', $coGroup);
}
+
+ /**
+ * Process an update to a CO Person's CO Group Memberships.
+ * - precondition: $this->request->params holds coperson
+ * - postcondition: Redirect generated
+ *
+ * @since COmanage Registry v0.8
+ */
+
+ public function update() {
+ if(!$this->restful) {
+ try {
+
$this->CoGroupMember->updateMemberships($this->request->data['CoGroupMember']['co_person_id'],
+
$this->request->data['CoGroupMember']['rows'],
+
$this->Session->read('Auth.User.co_person_id'));
+
+ $this->Session->setFlash(_txt('rs.saved'), '', array(), 'success');
+ }
+ catch(Exception $e) {
+ $this->Session->setFlash($e->getMessage(), '', array(), 'error');
+ }
+
+ // Issue redirect
+
+ $this->redirect(array('controller' => 'co_groups',
+ 'action' => 'select',
+ 'copersonid' =>
$this->request->data['CoGroupMember']['co_person_id'],
+ 'co' => $this->cur_co['Co']['id']));
+ }
+ }
}

Modified: registry/trunk/app/Controller/CoGroupsController.php
===================================================================
--- registry/trunk/app/Controller/CoGroupsController.php 2013-04-16
03:51:08 UTC (rev 501)
+++ registry/trunk/app/Controller/CoGroupsController.php 2013-04-19
20:42:56 UTC (rev 502)
@@ -267,13 +267,20 @@
$self = false;

if(!empty($roles['copersonid'])) {
- $own = $this->CoGroup->CoGroupMember->find('all', array('conditions' =>
-
array('CoGroupMember.co_person_id' => $roles['copersonid'],
-
'CoGroupMember.owner' => true)));
- $member = $this->CoGroup->CoGroupMember->find('all',
array('conditions' =>
-
array('CoGroupMember.co_person_id' => $roles['copersonid'],
-
'CoGroupMember.member' => true)));
+ $args = array();
+ $args['conditions']['CoGroupMember.co_person_id'] =
$roles['copersonid'];
+ $args['conditions']['CoGroupMember.owner'] = true;
+ $args['contain'] = false;

+ $own = $this->CoGroup->CoGroupMember->find('all', $args);
+
+ $args = array();
+ $args['conditions']['CoGroupMember.co_person_id'] =
$roles['copersonid'];
+ $args['conditions']['CoGroupMember.member'] = true;
+ $args['contain'] = false;
+
+ $member = $this->CoGroup->CoGroupMember->find('all', $args);
+
if(!empty($this->request->params['pass'][0])) {
$managed = $this->Role->isGroupManager($roles['copersonid'],
$this->request->params['pass'][0]);
}
@@ -317,14 +324,37 @@
$p['view'] = true;
}

+ if(isset($own)) {
+ // Set array of groups where person is owner
+
+ $p['owner'] = array();
+
+ foreach($own as $g) {
+ $p['owner'][] = $g['CoGroupMember']['co_group_id'];
+ }
+ }
+
+ if(isset($member)) {
+ // Set array of groups where person is member
+ $p['member'] = array();
+
+ foreach($member as $g) {
+ $p['member'][] = $g['CoGroupMember']['co_group_id'];
+ }
+ }
+
// Select from a list of potential Groups to join?
$p['select'] = ($roles['cmadmin']
|| ($managedp && $roles['coadmin'])
|| $self);

+ // Select from any Group (not just open or owned)?
+ $p['selectany'] = ($roles['cmadmin']
+ || ($managedp && $roles['coadmin']));
+
// View an existing Group?
$p['view'] = ($roles['cmadmin'] || $managed);
-
+
if($this->action == 'view'
&& isset($this->request->params['pass'][0])) {
// Adjust permissions for members and open groups
@@ -332,37 +362,17 @@
if(isset($member) && in_array($this->request->params['pass'][0],
$p['member']))
$p['view'] = true;

- $params = array(
- 'conditions' => array(
- 'CoGroup.id' => $this->request->params['pass'][0]
- )
- );
- $g = $this->CoGroup->find('first', $params);
+ $args = array();
+ $args['conditions']['CoGroup.id'] = $this->request->params['pass'][0];
+ $args['contain'] = false;

+ $g = $this->CoGroup->find('first', $args);
+
if(!empty($g) && isset($g['CoGroup']['open']) &&
$g['CoGroup']['open']) {
$p['view'] = true;
}
}
-
- if(isset($own))
- {
- // Set array of groups where person is owner
-
- $p['owner'] = array();
-
- foreach($own as $g)
- $p['owner'][] = $g['CoGroupMember']['co_group_id'];
- }
-
- if(isset($member))
- {
- // Set array of groups where person is member
- $p['member'] = array();
-
- foreach($member as $g)
- $p['member'][] = $g['CoGroupMember']['co_group_id'];
- }
-
+
$this->set('permissions', $p);
return $p[$this->action];
}

Modified: registry/trunk/app/Lib/enum.php
===================================================================
--- registry/trunk/app/Lib/enum.php 2013-04-16 03:51:08 UTC (rev 501)
+++ registry/trunk/app/Lib/enum.php 2013-04-19 20:42:56 UTC (rev 502)
@@ -25,6 +25,9 @@
class ActionEnum
{
// Codes beginning with 'X' (eg: 'XABC') are reserved for local use
+ const CoGroupMemberAdded = 'ACGM';
+ const CoGroupMemberDeleted = 'DCGM';
+ const CoGroupMemberEdited = 'ECGM';
const CoPersonAddedManual = 'ACPM';
const CoPersonAddedPetition = 'ACPP';
const CoPersonEditedManual = 'ECPM';

Modified: registry/trunk/app/Lib/lang.php
===================================================================
--- registry/trunk/app/Lib/lang.php 2013-04-16 03:51:08 UTC (rev 501)
+++ registry/trunk/app/Lib/lang.php 2013-04-19 20:42:56 UTC (rev 502)
@@ -109,6 +109,9 @@
// Enumerations, corresponding to enum.php
// Default history comments
'en.action' => array(
+ ActionEnum::CoGroupMemberAdded => 'CO Group Member Added',
+ ActionEnum::CoGroupMemberEdited => 'CO Group Member Edited',
+ ActionEnum::CoGroupMemberDeleted => 'CO Group Member Deleted',
ActionEnum::CoPersonAddedManual => 'CO Person Created (Manual)',
ActionEnum::CoPersonAddedPetition => 'CO Person Created
(Petition)',
ActionEnum::CoPersonEditedManual => 'CO Person Edited',
@@ -298,7 +301,7 @@
'er.cou.gr.admin' => 'COU created, but failed to create initial admin
group',
'er.cou.sameco' => 'COUs must be in the same CO',
'er.delete' => 'Delete Failed',
- 'er.deleted-a' => 'Deleted "%1$s"',
+ 'er.deleted-a' => 'Deleted "%1$s"', // XXX is this an er or an rs?
'er.db.connect' => 'Failed to connect to database: %1$s',
'er.db.schema' => 'Possibly failed to update database schema',
'er.db.save' => 'Database save failed',
@@ -320,6 +323,7 @@
'er.gr.nf' => 'Group %1$s Not Found',
'er.gr.res' => 'Groups named "admin" or prefixed "admin:" are
reserved',
'er.grm.already' => 'CO Person %1$s is already a member of group %2$s',
+ 'er.grm.nf' => 'Group Member %1$s Not Found',
'er.grm.none' => 'No group memberships to add',
'er.ia.already' => 'Identifier already assigned',
'er.ia.exists' => 'The identifier "%1$s" is already in use',
@@ -557,8 +561,9 @@
'op.edit-f' => 'Edit %1$s for %2$s',
'op.enroll' => 'Enroll',
'op.find.inv' => 'Find a Person to Invite to %1$s',
- 'op.gr.memadd' => 'Add %1$s to Group',
+ 'op.gr.memadd' => 'Manage %1$s Group Memberships',
'op.grm.add' => 'Add Person to %1$s Group %2$s',
+ 'op.grm.manage' => 'Manage My Group Memberships',
'op.history' => 'View History',
'op.id.auto' => 'Autogenerate Identifiers',
'op.id.auto.confirm' => 'Are you sure you wish to autogenerate
identifiers?',
@@ -592,6 +597,9 @@
// Results
'rs.added' => 'Added',
'rs.added-a' => '"%1$s" Added',
+ 'rs.grm.added' => 'Added to CO Group %1$s (%2$s) (member=%3$s,
owner=%4$s)',
+ 'rs.grm.deleted' => 'Removed from CO Group %1$s (%2$s)',
+ 'rs.grm.edited' => 'Edited CO Group Roles %1$s (%2$s) (from member=%3$s,
owner=%4$s to member=%5$s, owner=%6$s)',
'rs.ia.ok' => 'Identifiers Assigned',
'rs.inv.conf' => 'Invitation Confirmed',
'rs.inv.conf-a' => 'Invitation to %1$s confirmed',
@@ -609,6 +617,7 @@
'rs.pt.id.login' => 'Identifier "%1$s" flagged for login',
'rs.pt.login' => 'Petition Created. You have been logged out, and an
activation URL has been sent to your email address. Please click the link in
that email to continue.',
'rs.pt.relogin' => 'Petition Confirmed. You have been logged out, and
will need to login again for your new identity to take effect.',
+ 'rs.saved' => 'Saved',
'rs.updated' => '"%1$s" Updated',

// Setup
@@ -663,6 +672,12 @@
case 4:
return(sprintf($s, $vars[0], $vars[1], $vars[2], $vars[3]));
break;
+ case 5:
+ return(sprintf($s, $vars[0], $vars[1], $vars[2], $vars[3], $vars[4]));
+ break;
+ case 6:
+ return(sprintf($s, $vars[0], $vars[1], $vars[2], $vars[3], $vars[4],
$vars[5]));
+ break;
default:
return($s);
}

Modified: registry/trunk/app/Model/CoGroupMember.php
===================================================================
--- registry/trunk/app/Model/CoGroupMember.php 2013-04-16 03:51:08 UTC (rev
501)
+++ registry/trunk/app/Model/CoGroupMember.php 2013-04-19 20:42:56 UTC (rev
502)
@@ -121,4 +121,165 @@

return $ret;
}
+
+ /**
+ * Update the CO Group Memberships for a CO Person.
+ *
+ * @since COmanage Registry v0.8
+ * @param Integer CO Person ID
+ * @param Array Array of CO Group Member attributes (id, co_group_id,
member, owner)
+ * @param Integer CO Person ID of requester
+ * @return Boolean True on success, false otherwise
+ * @throws LogicException
+ */
+
+ public function updateMemberships($coPersonId, $memberships,
$requesterCoPersonId) {
+ if($coPersonId && !empty($memberships)) {
+ // First, pull the current group roles.
+
+ $curRoles = $this->findCoPersonGroupRoles($coPersonId);
+
+ foreach($memberships as $m) {
+ // Determine desired roles for this row
+ $member = isset($m['member']) && $m['member'];
+ $owner = isset($m['owner']) && $m['owner'];
+
+ // Pull the related group information
+ $args = array();
+ $args['conditions']['id'] = $m['co_group_id'];
+ $args['contain'] = false;
+
+ $grp = $this->CoGroup->find('first', $args);
+
+ if(empty($grp)) {
+ throw new InvalidArgumentException(_txt('er.gr.nf',
array($m['co_group_id'])));
+ }
+
+ if(!empty($m['id'])) {
+ $args = array();
+ $args['conditions']['id'] = $m['id'];
+ $args['contain'] = false;
+
+ $grpMem = $this->find('first', $args);
+
+ if(empty($grpMem)) {
+ throw new InvalidArgumentException(_txt('er.grm.nf',
array($m['id'])));
+ }
+
+ if(!$member && !$owner) {
+ // If a (CO Group Member) id is specified but member and owner
are
+ // both false, delete the row and cut a history record.
+
+ if(!$this->delete($m['id'])) {
+ throw new RuntimeException(_txt('er.delete'));
+ }
+
+ // Cut a history record
+
+ try {
+ $this->CoPerson->HistoryRecord->record($coPersonId,
+ null,
+ null,
+ $requesterCoPersonId,
+
ActionEnum::CoGroupMemberDeleted,
+ _txt('rs.grm.deleted',
array($grp['CoGroup']['name'],
+
$m['co_group_id'])));
+ }
+ catch(Exception $e) {
+ throw new RuntimeException($e->getMessage());
+ }
+ } else {
+ // Otherwise, update the row if the member or owner are
different than current.
+
+ $curMember = isset($grpMem['CoGroupMember']['member']) &&
$grpMem['CoGroupMember']['member'];
+ $curOwner = isset($grpMem['CoGroupMember']['owner']) &&
$grpMem['CoGroupMember']['owner'];
+
+ if(($member != $curMember) || ($owner != $curOwner)) {
+ $cogm = array();
+ $cogm['CoGroupMember']['id'] = $m['id'];
+ $cogm['CoGroupMember']['co_group_id'] = $m['co_group_id'];
+ $cogm['CoGroupMember']['co_person_id'] = $coPersonId;
+ $cogm['CoGroupMember']['member'] = $member;
+ $cogm['CoGroupMember']['owner'] = $owner;
+
+ if(!$this->save($cogm)) {
+ throw new RuntimeException($this->validationErrors);
+ }
+
+ // Cut a history record
+
+ try {
+ $this->CoPerson->HistoryRecord->record($coPersonId,
+ null,
+ null,
+ $requesterCoPersonId,
+
ActionEnum::CoGroupMemberEdited,
+ _txt('rs.grm.edited',
array($grp['CoGroup']['name'],
+
$m['co_group_id'],
+
_txt($grpMem['CoGroupMember']['member'] ? 'fd.yes' : 'fd.no'),
+
_txt($grpMem['CoGroupMember']['owner'] ? 'fd.yes' : 'fd.no'),
+
_txt($member ? 'fd.yes' : 'fd.no'),
+
_txt($owner ? 'fd.yes' : 'fd.no'))));
+ }
+ catch(Exception $e) {
+ throw new RuntimeException($e->getMessage());
+ }
+ }
+ }
+ } else {
+ // If id is not specified, that a role has been specified, make
sure
+ // the CO Person is not already in the group, that the group is in
the
+ // same CO as the CO Person, and add a new row.
+
+ if($member || $owner) {
+ if(!in_array($m['co_group_id'], $curRoles['member'])
+ && !in_array($m['co_group_id'], $curRoles['owner'])) {
+ if($grp['CoGroup']['co_id']
+ != $this->CoPerson->field('co_id', array('id' =>
$coPersonId))) {
+ throw new InvalidArgumentException(_txt('er.co.mismatch',
array("CoGroup", $m['co_group_id'])));
+ }
+
+ // We can finally add a new CoGroupMember
+
+ $cogm = array();
+ $cogm['CoGroupMember']['co_group_id'] = $m['co_group_id'];
+ $cogm['CoGroupMember']['co_person_id'] = $coPersonId;
+ $cogm['CoGroupMember']['member'] = $member;
+ $cogm['CoGroupMember']['owner'] = $owner;
+
+ if(!$this->save($cogm)) {
+ throw new RuntimeException($this->validationErrors);
+ }
+
+ // Cut a history record
+
+ try {
+ $this->CoPerson->HistoryRecord->record($coPersonId,
+ null,
+ null,
+ $requesterCoPersonId,
+
ActionEnum::CoGroupMemberAdded,
+ _txt('rs.grm.added',
array($grp['CoGroup']['name'],
+
$m['co_group_id'],
+
_txt($member ? 'fd.yes' : 'fd.no'),
+
_txt($owner ? 'fd.yes' : 'fd.no'))));
+ }
+ catch(Exception $e) {
+ throw new RuntimeException($e->getMessage());
+ }
+ } else {
+ // We shouldn't get here since $m['id'] should have been set
if the CO person
+ // already had a role in the group
+
+ throw new LogicException(_txt('er.grm.already',
array($coPersonId, $m['co_group_id'])));
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
}

Modified: registry/trunk/app/View/CoGroups/index.ctp
===================================================================
--- registry/trunk/app/View/CoGroups/index.ctp 2013-04-16 03:51:08 UTC (rev
501)
+++ registry/trunk/app/View/CoGroups/index.ctp 2013-04-19 20:42:56 UTC (rev
502)
@@ -33,26 +33,35 @@
}
print $this->element("pageTitle", $params);

- if($permissions['add'] && $this->action != 'select')
- echo $this->Html->link(_txt('op.add'),
- array('controller' => 'co_groups', 'action' =>
'add', 'co' => $this->request->params['named']['co']),
- array('class' => 'addbutton')) . '
+ if($permissions['add'] && $this->action != 'select') {
+ print $this->Html->link(_txt('op.add'),
+ array('controller' => 'co_groups',
+ 'action' => 'add',
+ 'co' => $cur_co['Co']['id']),
+ array('class' => 'addbutton'));
+
+ print $this->Html->link(_txt('op.grm.manage'),
+ array('controller' => 'co_groups',
+ 'action' => 'select',
+ 'copersonid' =>
$this->Session->read('Auth.User.co_person_id'),
+ 'co' => $cur_co['Co']['id']),
+ array('class' => 'linkbutton')) . '
<br />
<br />
';
-
- if($permissions['edit'] && $this->action == 'select')
- {
+ }
+
+ if($permissions['select'] && $this->action == 'select') {
// We're using slightly the wrong permission here... edit group instead
of add group member
// (though they work out the same)
- echo $this->Form->create('CoGroupMember',
- array('action' => 'add',
- 'inputDefaults' => array('label' => false,
- 'div' =>
false))) . "\n";
+ print $this->Form->create('CoGroupMember',
+ array('action' => 'update',
+ 'inputDefaults' => array('label' =>
false,
+ 'div' =>
false))) . "\n";
// beforeFilter needs CO ID
- echo $this->Form->hidden('CoGroupMember.co_id', array('default' =>
$cur_co['Co']['id'])) . "\n";
+ print $this->Form->hidden('CoGroupMember.co_id', array('default' =>
$cur_co['Co']['id'])) . "\n";
// Group ID must be global for isAuthorized
- echo $this->Form->hidden('CoGroupMember.co_person_id', array('default'
=> $this->request->params['named']['copersonid'])) . "\n";
+ print $this->Form->hidden('CoGroupMember.co_person_id', array('default'
=> $this->request->params['named']['copersonid'])) . "\n";
}
?>

@@ -110,18 +119,52 @@
</td>
<td>
<?php
- if($this->action == 'select')
- {
- if($permissions['select'])
- {
- echo $this->Form->hidden('CoGroupMember.'.$i.'.co_group_id',
- array('default' =>
$c['CoGroup']['id'])) . "\n";
- echo $this->Form->checkbox('CoGroupMember.'.$i.'.member') .
_txt('fd.group.mem') . "\n";
- echo $this->Form->checkbox('CoGroupMember.'.$i.'.owner') .
_txt('fd.group.own') . "\n";
+ if($this->action == 'select') {
+ if($permissions['select']) {
+ print
$this->Form->hidden('CoGroupMember.rows.'.$i.'.co_group_id',
+ array('default' =>
$c['CoGroup']['id'])) . "\n";
+
+ // We toggle the disabled status of the checkbox based on a
person's permissions.
+ // A CO(U) Admin can edit any membership or ownership.
+ // A group owner can edit any membership or ownership for that
group.
+ // Anyone can add or remove themself from or two an open group.
+
+ $gmID = null;
+ $isMember = false;
+ $isOwner = false;
+
+ foreach($c['CoGroupMember'] as $cgm) {
+ // Walk the CoGroupMemberships for this CoGroup to find the
target CO Person
+ if($cgm['co_person_id'] ==
$this->request->params['named']['copersonid']) {
+ $gmID = $cgm['id'];
+ $isMember = $cgm['member'];
+ $isOwner = $cgm['owner'];
+ break;
+ }
+ }
+
+ if($gmID) {
+ // Populate the cross reference
+ print $this->Form->hidden('CoGroupMember.rows.'.$i.'.id',
+ array('default' => $gmID)) . "\n";
+ }
+
+ print $this->Form->checkbox('CoGroupMember.rows.'.$i.'.member',
+ array('disabled' =>
!($permissions['selectany']
+ ||
$c['CoGroup']['open']
+ || $isMember
+ || $isOwner),
+ 'checked' => $isMember))
+ . _txt('fd.group.mem') . "\n";
+
+ print $this->Form->checkbox('CoGroupMember.rows.'.$i.'.owner',
+ array('disabled' =>
!($permissions['selectany']
+ || $isOwner),
+ 'checked' => $isOwner))
+ . _txt('fd.group.own') . "\n";
}
}
- else
- {
+ else {
if($e)
echo $this->Html->link(_txt('op.edit'),
array('controller' => 'co_groups', 'action'
=> 'edit', $c['CoGroup']['id'], 'co' =>
$this->request->params['named']['co']),
@@ -147,10 +190,11 @@
<tr>
<td>
<?php
- if($this->action == 'select')
- echo $this->Form->submit(_txt('op.add'));
+ if($this->action == 'select') {
+ print $this->Form->submit(_txt('op.save'));
+ }

- echo $this->Form->end();
+ print $this->Form->end();
?>
</td>
</tr>



  • [comanage-dev] r502 - in registry/trunk/app: Controller Lib Model View/CoGroups, svnlog, 04/19/2013

Archive powered by MHonArc 2.6.16.

Top of Page