Commit 86d8cc21 authored by Son Nguyen's avatar Son Nguyen
Browse files

Enable collections in groups and institutions (Bug #886080)



1. For group collections
Only roles that can edit group pages can do these:
- Listing group collections
- Creating a new group collection
- Deleting and editing an selected group collection.
- Copying a collection
2. For institution collections
Only institution admins can:
- Listing insitution collections
- Creating a new institution collection
- Deleting and editing an selected institution collection.
- Copying a collection

Change-Id: I799bcfaf0f751d1a8c1fa9b5e5df4832832d8ea1
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent e5bdacad
...@@ -72,7 +72,7 @@ class PluginArtefactFile extends PluginArtefact { ...@@ -72,7 +72,7 @@ class PluginArtefactFile extends PluginArtefact {
'path' => 'groups/files', 'path' => 'groups/files',
'url' => 'artefact/file/groupfiles.php?group='.$groupid, 'url' => 'artefact/file/groupfiles.php?group='.$groupid,
'title' => get_string('Files', 'artefact.file'), 'title' => get_string('Files', 'artefact.file'),
'weight' => 70, 'weight' => 80,
), ),
); );
} }
......
...@@ -1033,9 +1033,22 @@ class User { ...@@ -1033,9 +1033,22 @@ class User {
*/ */
public function can_edit_collection($c) { public function can_edit_collection($c) {
$owner = $c->get('owner'); $owner = $c->get('owner');
if ($owner == $this->get('id')) { if ($owner > 0 && $owner == $this->get('id')) {
return true;
}
$institution = $c->get('institution');
if ($institution && $this->can_edit_institution($institution)) {
return true; return true;
} }
$group = $c->get('group');
if ($group) {
$this->reset_grouproles();
if (!isset($this->grouproles[$group])) {
return false;
}
require_once('group.php');
return group_role_can_edit_views($group, $this->grouproles[$group]);
}
return false; return false;
} }
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
...@@ -35,14 +34,39 @@ define('SECTION_PAGE', 'delete'); ...@@ -35,14 +34,39 @@ define('SECTION_PAGE', 'delete');
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
define('TITLE', get_string('deletecollection', 'collection'));
$id = param_integer('id'); $id = param_integer('id');
$collection = new Collection($id); $collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) { if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('cantdeletecollection', 'collection')); throw new AccessDeniedException(get_string('cantdeletecollection', 'collection'));
redirect('/collection/'); }
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
}
define('TITLE', get_string('deletespecifiedcollection', 'collection', $collection->get('name')));
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
} }
if ($collection->is_submitted()) { if ($collection->is_submitted()) {
...@@ -57,20 +81,20 @@ $form = pieform(array( ...@@ -57,20 +81,20 @@ $form = pieform(array(
'submit' => array( 'submit' => array(
'type' => 'submitcancel', 'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')), 'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'collection/', 'goto' => $baseurl,
), ),
), ),
)); ));
$smarty = smarty(); $smarty = smarty();
$smarty->assign('subheading', TITLE); $smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('message', get_string('collectionconfirmdelete', 'collection')); $smarty->assign('message', get_string('collectionconfirmdelete', 'collection'));
$smarty->assign('form', $form); $smarty->assign('form', $form);
$smarty->display('collection/delete.tpl'); $smarty->display('collection/delete.tpl');
function deletecollection_submit(Pieform $form, $values) { function deletecollection_submit(Pieform $form, $values) {
global $SESSION, $collection; global $SESSION, $collection, $baseurl;
$collection->delete(); $collection->delete();
$SESSION->add_ok_msg(get_string('collectiondeleted', 'collection')); $SESSION->add_ok_msg(get_string('collectiondeleted', 'collection'));
redirect('/collection/'); redirect($baseurl);
} }
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
...@@ -37,33 +36,86 @@ require_once('pieforms/pieform.php'); ...@@ -37,33 +36,86 @@ require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
$new = param_boolean('new', 0); $new = param_boolean('new', 0);
$id = !$new ? param_integer('id') : 0; $copy = param_boolean('copy', 0);
$collection = new Collection($id); if ($new) { // if creating a new collection
if (!$USER->can_edit_collection($collection)) { $owner = null;
$SESSION->add_error_msg(get_string('canteditdontown', 'collection')); $groupid = param_integer('group', 0);
redirect('/collection/'); $institutionname = param_alphanum('institution', false);
if (empty($groupid) && empty($institutionname)) {
$owner = $USER->get('id');
}
$collection = new Collection(null, array('owner' => $owner, 'group' => $groupid, 'institution' => $institutionname));
define('SUBTITLE', get_string('edittitleanddesc', 'collection'));
}
else { // if editing an existing or copied collection
$id = param_integer('id');
$collection = new Collection($id);
$owner = $collection->get('owner');
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
define('SUBTITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection'));
} }
if ($collection->is_submitted()) { if ($collection->is_submitted()) {
$submitinfo = $collection->submitted_to(); $submitinfo = $collection->submitted_to();
throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name)); throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
} }
// if not a new collection $urlparams = array();
if (!$new) { if (!empty($groupid)) {
define('TITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection')); define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
define('TITLE', get_string('editcollection', 'collection'));
$urlparams['institution'] = $institutionname;
} }
else { else {
define('TITLE', get_string('edittitleanddesc', 'collection')); define('MENUITEM', 'myportfolio/collection');
define('TITLE', get_string('editcollection', 'collection'));
}
if (!$USER->can_edit_collection($collection)) {
throw new AccessDeniedException(get_string('canteditcollection', 'collection'));
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
} }
$elements = $collection->get_collectionform_elements(); $elements = $collection->get_collectionform_elements();
$submitstr = $new ? array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection'))
: array(get_string('save'), get_string('cancel'));
$confirm = $new ? array('cancel' => get_string('confirmcancelcreatingcollection','collection')) : null;
if ($copy) {
$type = 'submit';
$submitstr = get_string('next') . ': ' . get_string('editviews', 'collection');
$confirm = null;
}
else {
$type = 'submitcancel';
if ($new) {
$submitstr = array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection'));
$confirm = array('cancel' => get_string('confirmcancelcreatingcollection','collection'));
}
else {
$submitstr = array(get_string('save'), get_string('cancel'));
$confirm = null;
}
}
$elements['submit'] = array( $elements['submit'] = array(
'type' => 'submitcancel', 'type' => $type,
'value' => $submitstr, 'value' => $submitstr,
'confirm' => $confirm, 'confirm' => $confirm,
); );
...@@ -77,24 +129,28 @@ $form = pieform(array( ...@@ -77,24 +129,28 @@ $form = pieform(array(
)); ));
$smarty = smarty(); $smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE); if (!empty($groupid)) {
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->assign('PAGEHELPNAME', '0');
$smarty->assign('SUBPAGEHELPNAME', '1');
}
else {
$smarty->assign('PAGEHEADING', SUBTITLE);
}
$smarty->assign_by_ref('form', $form); $smarty->assign_by_ref('form', $form);
$smarty->display('collection/edit.tpl'); $smarty->display('collection/edit.tpl');
function submit(Pieform $form, $values) { function submit(Pieform $form, $values) {
global $SESSION, $new; global $SESSION, $new, $copy, $urlparams;
$values['navigation'] = (int) $values['navigation']; $values['navigation'] = (int) $values['navigation'];
$collection = Collection::save($values); $collection = Collection::save($values);
if (!$new) { if (!$new) {
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection')); $SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
} }
$collection->post_edit_redirect($new); $collection->post_edit_redirect($new, $copy, $urlparams);
} }
function edit_cancel_submit() { function edit_cancel_submit() {
global $collection, $new; global $baseurl;
if ($new && $collection) { redirect($baseurl);
$collection->delete();
}
redirect('/collection/');
} }
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
define('SECTION_PAGE', 'index'); define('SECTION_PAGE', 'index');
...@@ -35,13 +33,75 @@ define('SECTION_PAGE', 'index'); ...@@ -35,13 +33,75 @@ define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
define('TITLE', get_string('Collections', 'collection'));
// offset and limit for pagination // offset and limit for pagination
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 5); $limit = param_integer('limit', 5);
$data = Collection::get_mycollections_data($offset, $limit); $owner = null;
$groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false);
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
// Check if user can edit group collections <-> user can edit group views
$role = group_user_access($group->id);
$canedit = $role && group_role_can_edit_views($group, $role);
if (!$canedit) {
throw new GroupAccessDeniedException(get_string('cantlistgroupcollections', 'collection'));
}
define('SUBTITLE', get_string('groupcollections', 'collection'));
define('TITLE', $group->name);
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
define('TITLE', get_string('sitecollections', 'collection'));
// Check if user is a site admin
$canedit = $USER->get('admin');
if (!$canedit) {
throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
}
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
define('TITLE', get_string('institutioncollections', 'collection'));
// Check if user is a institution admin
$canedit = $USER->get('admin') || $USER->is_institutional_admin();
if (!$canedit) {
throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
}
require_once('institution.php');
// Get list of availlable institutions
$s = institution_selector_for_page($institutionname, get_config('wwwroot') . 'collection/index.php');
$institutionname = $s['institution'];
if ($institutionname === false) {
$smarty = smarty();
$smarty->display('admin/users/noinstitutions.tpl');
exit;
}
}
define('SUBTITLE', '');
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
$owner = $USER->get('id');
define('SUBTITLE', '');
define('TITLE', get_string('Collections', 'collection'));
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
}
$data = Collection::get_mycollections_data($offset, $limit, $owner, $groupid, $institutionname);
foreach ($data->data as $value) { foreach ($data->data as $value) {
$collection = new Collection($value->id); $collection = new Collection($value->id);
$views = $collection->get('views'); $views = $collection->get('views');
...@@ -53,7 +113,7 @@ foreach ($data->data as $value) { ...@@ -53,7 +113,7 @@ foreach ($data->data as $value) {
$pagination = build_pagination(array( $pagination = build_pagination(array(
'id' => 'collectionslist_pagination', 'id' => 'collectionslist_pagination',
'class' => 'center', 'class' => 'center',
'url' => get_config('wwwroot') . 'collection/index.php', 'url' => $baseurl,
'count' => $data->count, 'count' => $data->count,
'limit' => $data->limit, 'limit' => $data->limit,
'offset' => $data->offset, 'offset' => $data->offset,
...@@ -67,9 +127,20 @@ $pagination = build_pagination(array( ...@@ -67,9 +127,20 @@ $pagination = build_pagination(array(
)); ));
$smarty = smarty(array('paginator')); $smarty = smarty(array('paginator'));
$urlparamsstr = '';
if ($urlparams) {
$urlparamsstr = '&' . http_build_query($urlparams);
}
$smarty->assign('addonelink', get_config('wwwroot') . 'collection/edit.php?new=1' . $urlparamsstr);
if (!empty($institutionname) && ($institutionname != 'mahara')) {
$smarty->assign('institution', $institutionname);
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
}
$smarty->assign('urlparamsstr', $urlparamsstr);
$smarty->assign('collections', $data->data); $smarty->assign('collections', $data->data);
$smarty->assign('pagination', $pagination['html']); $smarty->assign('pagination', $pagination['html']);
$smarty->assign('strnocollectionsaddone',
get_string('nocollectionsaddone','collection','<a href="' . get_config('wwwroot') . 'collection/edit.php?new=1">', '</a>'));
$smarty->assign('PAGEHEADING', TITLE); $smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->display('collection/index.tpl'); $smarty->display('collection/index.tpl');
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
...@@ -44,16 +43,45 @@ $direction = param_variable('direction',''); ...@@ -44,16 +43,45 @@ $direction = param_variable('direction','');
$collection = new Collection($id); $collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) { if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection')); throw new AccessDeniedException(get_string('canteditcollection', 'collection'));
redirect('/collection/'); }
$owner = $collection->get('owner');
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
define('TITLE', get_string('editcollection', 'collection'));
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
define('TITLE', get_string('editcollection', 'collection'));
}
define('SUBTITLE', $collection->get('name'). ': ' . get_string('editviews', 'collection'));
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
} }
if ($collection->is_submitted()) { if ($collection->is_submitted()) {
$submitinfo = $collection->submitted_to(); $submitinfo = $collection->submitted_to();
throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name)); throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
} }
define('TITLE', $collection->get('name') . ': ' . get_string('editviews', 'collection'));
if ($view AND !empty($direction)) { if ($view AND !empty($direction)) {
$collection->set_viewdisplayorder($view,$direction); $collection->set_viewdisplayorder($view,$direction);
redirect('/collection/views.php?id='.$id); redirect('/collection/views.php?id='.$id);
...@@ -83,7 +111,7 @@ if ($views) { ...@@ -83,7 +111,7 @@ if ($views) {
$elements = array(); $elements = array();
$viewsform = null; $viewsform = null;
if ($available = Collection::available_views()) { if ($available = Collection::available_views($owner, $groupid, $institutionname)) {
foreach ($available as $a) { foreach ($available as $a) {
$elements['view_'.$a->id] = array( $elements['view_'.$a->id] = array(
'type' => 'checkbox', 'type' => 'checkbox',
...@@ -108,7 +136,15 @@ if ($available = Collection::available_views()) { ...@@ -108,7 +136,15 @@ if ($available = Collection::available_views()) {
$smarty = smarty(); $smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE); if (!empty($groupid)) {
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->assign('PAGEHELPNAME', '0');
$smarty->assign('SUBPAGEHELPNAME', '1');
}
else {
$smarty->assign('PAGEHEADING', SUBTITLE);
}
$smarty->assign('baseurl', $baseurl);
$smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id); $smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id);
$smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id); $smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id);
$smarty->assign_by_ref('views', $views); $smarty->assign_by_ref('views', $views);
......
...@@ -40,6 +40,12 @@ $string['add'] = 'Add'; ...@@ -40,6 +40,12 @@ $string['add'] = 'Add';
$string['addviews'] = 'Add pages'; $string['addviews'] = 'Add pages';
$string['addviewstocollection'] = 'Add pages to collection'; $string['addviewstocollection'] = 'Add pages to collection';
$string['back'] = 'Back'; $string['back'] = 'Back';
$string['cantlistgroupcollections'] = 'You are not allowed to list group collections.';
$string['cantlistinstitutioncollections'] = 'You are not allowed to list institution collections.';
$string['canteditgroupcollections'] = 'You are not allowed to edit group collections.';
$string['canteditinstitutioncollections'] = 'You are not allowed to edit institution collections.';
$string['canteditcollection'] = 'You are not allowed to edit this collection.';
$string['cantcreatecollection'] = 'You are not allowed to create this collection.';
$string['cantdeletecollection'] = 'You cannot delete this collection.'; $string['cantdeletecollection'] = 'You cannot delete this collection.';
$string['canteditdontown'] = 'You cannot edit this collection because you do not own it.'; $string['canteditdontown'] = 'You cannot edit this collection because you do not own it.';
$string['canteditsubmitted'] = 'You can\'t edit this collection because it has been submitted for assessment to %s. You will have to wait until a tutor releases it.'; $string['canteditsubmitted'] = 'You can\'t edit this collection because it has been submitted for assessment to %s. You will have to wait until a tutor releases it.';
...@@ -47,6 +53,9 @@ $string['collection'] = 'collection'; ...@@ -47,6 +53,9 @@ $string['collection'] = 'collection';
$string['Collection'] = 'Collection'; $string['Collection'] = 'Collection';
$string['collections'] = 'Collections'; $string['collections'] = 'Collections';
$string['Collections'] = 'Collections'; $string['Collections'] = 'Collections';
$string['groupcollections'] = 'Group collections';
$string['institutioncollections'] = 'Institution collections';
$string['sitecollections'] = 'Site collections';
$string['collectionaccess'] = 'Collection access'; $string['collectionaccess'] = 'Collection access';
$string['collectionaccesseditedsuccessfully'] = 'Collection access saved successfully';