Commit 28390994 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Get editable status along with artefactchooser artefacts (bug #736665)



When choosing an artefact for inclusion in a view, add a boolean
property to indicate whether each returned artefact is editable in
the context of the view.  So, individual artefacts are editable in
individual views provided the 'owner' is the same, group artefacts
are editable when the group is the same as the view's group, etc.

Change-Id: I3ec7d13d5401ddd007916f9382fd0673739dd815
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent a65e40c4
......@@ -100,7 +100,7 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
'selectone' => true,
'selectjscallback' => 'updateTextContent',
'getblocks' => true,
'returnfields' => array('id', 'title', 'description'),
'returnfields' => array('id', 'title', 'description', 'editable'),
'artefacttypes' => array('html'),
'template' => 'artefact:internal:html-artefactchooser-element.tpl',
);
......
......@@ -2345,7 +2345,7 @@ class View {
$from .= '
LEFT OUTER JOIN (
SELECT
r.artefact, r.can_view, m.group
r.artefact, r.can_view, r.can_edit, m.group
FROM
{artefact_access_role} r
INNER JOIN {group_member} m ON r.role = m.role
......@@ -2412,11 +2412,39 @@ class View {
$select .= $extraselect;
$cols = $short ? 'a.id, a.id AS b' : 'a.*'; // get_records_sql_assoc wants > 1 column
if ($short) {
// We just want to know which artefact ids are allowed for inclusion in a view,
// but get_records_sql_assoc wants > 1 column
$cols = 'a.id, a.id AS b';
$ph = array();
}
else {
$cols = 'a.*';
// We also want to know which artefacts can be edited by the logged-in user within
// the context of the view. For an institution view, all artefacts from the same
// institution are editable. For an individual view, artefacts with the same 'owner'
// are editable. For group views, only those artefacts with the can_edit permission
// out of artefact_access_role are editable.
if ($group) {
$expr = 'ga.can_edit IS NOT NULL AND ga.can_edit = 1';
$ph = array();
}
else if ($institution) {
$expr = 'a.institution = ?';
$ph = array($institution);
}
else {
$expr = 'a.owner IS NOT NULL AND a.owner = ?';
$ph = array($user->get('id'));
}
$type = is_mysql() ? 'UNSIGNED' : 'INTEGER';
$cols .= ", CAST($expr AS $type) AS editable";
}
$artefacts = get_records_sql_assoc(
'SELECT ' . $cols . $from . ' WHERE ' . $select . $sortorder,
null, $offset, $limit
'SELECT ' . $cols . $from . ' WHERE ' . $select . $sortorder, $ph, $offset, $limit
);
$totalartefacts = count_records_sql('SELECT COUNT(*) ' . $from . ' WHERE ' . $select);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment