Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: Added resource copy policies method / a community admin can now …
Browse files Browse the repository at this point in the history
…add a user

ENH: Added resource copy policies method

ENH: A community admin can now add a user (no invitation required)

Removed netbeans files (added by mistake)

Fixed trailing spaces issues

Fixed addtouser test

Fixed typo and cleaned gitignore
  • Loading branch information
Charles Marion authored and Jamie Snape committed Nov 20, 2014
1 parent b22e141 commit b8d8de3
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 2 deletions.
42 changes: 42 additions & 0 deletions core/controllers/CommunityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ public function invitationAction()
$this->disableLayout();

$communityId = $this->getParam('communityId');
$directAdd = $this->_getParam('directadd');
if (isset($directAdd) && $directAdd == "true") {
$directAdd = 1;
} else {
$directAdd = 0;
}

if (!isset($communityId)) {
throw new Zend_Exception('Must pass a communityId parameter');
}
Expand All @@ -484,6 +491,41 @@ public function invitationAction()
) {
throw new Zend_Exception('Write permission required on the community', 403);
}

$this->view->directAdd = $directAdd;
}

/**
* Ajax method for adding a user to a community group
* @param communityId Id of the community to invite into
* @param [groupId] Id of the group to invite into. If none is passed, uses the members group
* @param [userId] Id of the user to invite. If not passed, must pass email parameter
* @param [email] Email of the user to invite. If not passed, must pass userId parameter.
* If no such user exists, sends an email inviting the user to register and join the group.
*/
public function addusertogroupAction()
{
$this->disableLayout();
$this->disableView();

$communityId = $this->_getParam('communityId');
$userId = $this->_getParam('userId');

$community = $this->Community->load($communityId);
if (!$community || !$this->Community->policyCheck($community, $this->userSession->Dao, MIDAS_POLICY_ADMIN)) {
throw new Zend_Exception('Admin permission required on the community', 403);
}

$group = $this->Group->load($this->_getParam('groupId'));
$user = $this->User->load($userId);
if ($group && $user) {
$member_group = $community->getMemberGroup();
$this->Group->addUser($member_group, $user);
$this->Group->addUser($group, $user);
echo JsonComponent::encode(array(true, 'User added.'));
} else {
echo JsonComponent::encode(array(false, 'Unable to add user.'));
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions core/models/base/FolderModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ abstract public function getMaxPolicy($folderId, $user);
/** Zip stream */
abstract public function zipStream(&$zip, $path, $folder, &$userDao, &$overrideOutputFunction = null);


/** copy another folder's policies */
public function copyFolderPolicies($folderdao, $referenceFolderdao)
{
if (!$folderdao instanceof FolderDao || !$referenceFolderdao instanceof FolderDao) {
throw new Zend_Exception("Error in param folderdao or referenceFolderdao when copying parent policies.");
}
$groupPolicies = $referenceFolderdao->getFolderpolicygroup();
$userPolicies = $referenceFolderdao->getFolderpolicyuser();

$FolderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');
foreach ($groupPolicies as $key => $policy) {
$FolderpolicygroupModel->createPolicy($policy->getGroup(), $folderdao, $policy->getPolicy());
}
$FolderpolicyuserModel = MidasLoader::loadModel('Folderpolicyuser');
foreach ($userPolicies as $key => $policy) {
$FolderpolicyuserModel->createPolicy($policy->getUser(), $folderdao, $policy->getPolicy());
}
}

/** Get the root folder */
public function getRoot($folder)
{
Expand Down
30 changes: 30 additions & 0 deletions core/models/base/ItemModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ abstract public function existsInFolder($name, $folder);
/** Update item name */
abstract public function updateItemName($name, $parent);

/** copy another item's policies */
public function copyItemPolicies($itemdao, $referenceItemdao, $feeddao = null)
{
if (!$itemdao instanceof ItemDao || !$referenceItemdao instanceof ItemDao) {
throw new Zend_Exception("Error in param itemdao or referenceItemdao when copying parent policies.");
}
$groupPolicies = $referenceItemdao->getItempolicygroup();
$userPolicies = $referenceItemdao->getItempolicyuser();

$ItempolicygroupModel = MidasLoader::loadModel('Itempolicygroup');
foreach ($groupPolicies as $key => $policy) {
$ItempolicygroupModel->createPolicy($policy->getGroup(), $itemdao, $policy->getPolicy());
}
$ItempolicyuserModel = MidasLoader::loadModel('Itempolicyuser');
foreach ($userPolicies as $key => $policy) {
$ItempolicyuserModel->createPolicy($policy->getUser(), $itemdao, $policy->getPolicy());
}

if ($feeddao != null && $feeddao instanceof FeedDao) {
$FeedpolicygroupModel = MidasLoader::loadModel('Feedpolicygroup');
foreach ($groupPolicies as $key => $policy) {
$FeedpolicygroupModel->createPolicy($policy->getGroup(), $feeddao, $policy->getPolicy());
}
$FeedpolicyuserModel = MidasLoader::loadModel('Feedpolicyuser');
foreach ($userPolicies as $key => $policy) {
$FeedpolicyuserModel->createPolicy($policy->getUser(), $feeddao, $policy->getPolicy());
}
}
}

/** delete an item */
public function delete($dao)
{
Expand Down
2 changes: 1 addition & 1 deletion core/public/js/community/community.invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var midas = midas || {};
midas.invite = midas.invite || {};

var jsonShare = $.parseJSON($('div.jsonShareContent').html());
midas.invite.directAdd = $("#directAdd").val();

/**
* Render group selection dialog for the community
Expand Down
5 changes: 5 additions & 0 deletions core/public/js/community/community.manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ midas.community.manage.init = function () {
});
});

$('a#addUserToGroupLink').click(function () {
midas.loadDialog("invitationCommunity", "/community/invitation?directadd=true&communityId=" + json.community.community_id);
midas.showDialog(json.community.sendInvitation, false);
});

$('a.editGroupLink').click(function () {
mainDialogContentDiv.html('');
var id = $(this).attr('groupid');
Expand Down
8 changes: 8 additions & 0 deletions core/public/js/community/community.selectgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var midas = midas || {};
$(document).ready(function () {
'use strict';
$('#groupSelectOk').click(function () {
var url = json.global.webroot + '/community/sendinvitation';
var params = {
communityId: json.community.community_id,
groupId: $('#groupSelect').val()
Expand All @@ -17,10 +18,17 @@ $(document).ready(function () {
else {
params[midas.invite.item.key] = midas.invite.item.value;
}
if (typeof midas.invite.directAdd !== "undefined" && midas.invite.directAdd == 1) {
url = json.global.webroot + '/community/addusertogroup'
}
$.post(json.global.webroot + '/community/sendinvitation', params, function (data) {
var jsonResponse = $.parseJSON(data);
if (jsonResponse[0]) {
midas.createNotice(jsonResponse[1], 3000);
if (typeof midas.invite.directAdd !== "undefined" && midas.invite.directAdd == 1) {
window.location.href = json.global.webroot + "/community/manage?communityId=" + json.community.community_id + "#tabs-Users";
window.location.reload();
}
$('div.MainDialog').dialog('close');
}
else {
Expand Down
27 changes: 27 additions & 0 deletions core/tests/controllers/CommunityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,33 @@ public function testSelectgroupAction()
$this->assertQuery('option[value="'.$comm->getAdmingroupId().'"]');
}

/**
* Test addusertogroup action
*/
public function testAddusertogroupAction()
{
$commFile = $this->loadData('Community', 'default');
$userFile = $this->loadData('User', 'default');
$comm = $this->Community->load($commFile[0]->getKey());
$user1 = $this->User->load($userFile[0]->getKey());
$user2 = $this->User->load($userFile[1]->getKey());

// Anonymous users should get exception
$this->dispatchUrI('/community/addusertogroup?communityId='.$comm->getKey(), null, true);

// Have user 1 join the community as a member; should not be able to see dialog
$this->Group->removeUser($comm->getMemberGroup(), $user2);
$this->Group->removeUser($comm->getAdminGroup(), $user2);
$this->Group->addUser($comm->getMemberGroup(), $user1);
$this->Group->addUser($comm->getAdminGroup(), $user1);
$this->resetAll();
$this->dispatchUrI('/community/addusertogroup?communityId='.$comm->getKey()
.'&groupId='.$comm->getAdminGroup()->getKey()
.'&userId='.$user2->getKey(), $user1);

$this->assertTrue($this->Group->userInGroup($user2, $comm->getAdminGroup()));
}

/**
* Test sendinvitation action
*/
Expand Down
2 changes: 2 additions & 0 deletions core/views/community/invitation.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/commu
<link href="<?php echo $this->coreWebroot ?>/public/css/community/community.invitation.css" rel="stylesheet"
type="text/css"/>

<input type='hidden' id='directAdd' value='<?php echo $this->directAdd ?>' />

<div class='invitationSearch'>
<input type='text' id='live_invitation_search' value='Start typing a name or email address...' autocomplete='off'
autocorrect='off' autocapitalize='off'/>
Expand Down
2 changes: 1 addition & 1 deletion core/views/community/manage.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ if ($this->isAdmin) {
?>
</div>
<hr>
<a href="javascript:;" id='createGroupLink'> <?php echo $this->t('Create a new group') ?></a>
<a href="javascript:;" id='createGroupLink'> <?php echo $this->t('Create a new group') ?></a>, , <a href="javascript:;" id='addUserToGroupLink'> <?php echo $this->t('Add user to group') ?></a>

<div style="display:none;" id='createGroupFrom'>
<form class="editGroupForm genericForm" method="<?php echo $this->createGroupForm['method'] ?>"
Expand Down

0 comments on commit b8d8de3

Please sign in to comment.