Commit d07127c9 authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Merge "Support for collections in "Shared with me" screen (Bug 1476495)"

parents 8d2dd779 0958d6c0
......@@ -4051,6 +4051,40 @@ class View {
OR qu.username $like '%' || ? || '%' ";
array_push($whereparams, $query);
}
if ($groupbycollection) {
$where .= "OR EXISTS (
SELECT 1
FROM
{view} v2
INNER JOIN {collection_view} cv2
ON v2.id=cv2.view
AND cv2.collection = cv.collection
INNER JOIN {collection} c2
ON c2.id = cv2.collection
LEFT OUTER JOIN {view_tag} vt
ON (vt.view = v2.id AND vt.tag = ?)
LEFT OUTER JOIN {collection_tag} ct
ON (ct.collection = cv2.collection AND ct.tag = ?)
WHERE
v2.title $like '%' || ? || '%'
OR v2.description $like '%' || ? || '%'
OR c2.name $like '%' || ? || '%'
OR c2.description $like '%' || ? || '%'
OR vt.tag = ?
OR ct.tag = ?
)";
array_push(
$whereparams,
$query,
$query,
$query,
$query,
$query,
$query,
$query,
$query
);
}
$where .= ")";
}
else if ($tag) { // Filter by the tag
......@@ -4374,16 +4408,29 @@ class View {
$result = self::view_search(
$query, null, null, null, $limit, $offset,
true, $sort, array('portfolio'), false, $accesstypes, $tag,
null, $userid
null, $userid, true
);
if (!$result->count) {
return $result;
}
$viewids = array();
$collids = array();
foreach ($result->data as $rec) {
if ($rec['collid']) {
$collids[] = $rec['collid'];
}
else {
$viewids[] = $rec['viewid'];
}
}
// Get additional data: number of comments, last commenter
$commentdata = get_records_sql_assoc(
'
$viewcommentdata = array();
if ($viewids) {
$viewcommentdata = get_records_sql_assoc(
'
SELECT
acc.onview AS id,
a.mtime AS lastcommenttime,
......@@ -4391,6 +4438,7 @@ class View {
a.authorname AS commentauthorname,
a.id AS commentid,
a.description AS commenttext,
acc.onview AS lastcommentviewid,
(SELECT COUNT(*) FROM {artefact_comment_comment} c WHERE c.onview = acc.onview AND c.deletedby IS NULL AND c.private=0) AS commentcount
FROM
{artefact_comment_comment} acc
......@@ -4412,17 +4460,87 @@ class View {
ORDER BY a3.mtime DESC, acc2.artefact ASC
LIMIT 1
)
AND acc.onview IN (' . join(',', array_fill(0, count($result->data), '?')) . ')
',
$result->ids
);
$fields = array('lastcommenttime', 'commentauthor', 'commentauthorname', 'commenttext', 'commentid', 'commentcount');
AND acc.onview IN (' . join(',', array_fill(0, count($viewids), '?')) . ')
',
$viewids
);
}
// Get additional data about comments on collections
// (Splitting this into a separate query to make the code simpler)
$collectioncommentdata = array();
if ($collids) {
$collectioncommentdata = get_records_sql_assoc(
'
-- Get the full information about the artefact that
-- matches the subquery
SELECT
cv.collection AS collectionid,
a.mtime AS lastcommenttime,
a.author AS commentauthor,
a.authorname AS commentauthorname,
a.id AS commentid,
a.description AS commenttext,
acc.onview as lastcommentviewid,
(
SELECT COUNT(*)
FROM
{artefact_comment_comment} c
INNER JOIN {collection_view} cv2
ON c.onview = cv2.view
WHERE
cv2.collection = cv.collection
AND c.deletedby IS NULL
AND c.private=0
) AS commentcount
FROM
{artefact_comment_comment} acc
INNER JOIN {artefact} a
ON acc.artefact = a.id
LEFT OUTER JOIN {collection_view} cv
ON cv.view = acc.onview
WHERE
acc.artefact = (
-- Get all the comments on all the views that are in the same collection as this artefact
-- order them by mtime, and limit to 1
SELECT acc2.artefact
FROM
{artefact_comment_comment} acc2
INNER JOIN {artefact} a3
ON acc2.artefact = a3.id
INNER JOIN {collection_view} cv2
ON acc2.onview = cv2.view
WHERE
acc2.deletedby IS NULL
AND acc2.private = 0
AND cv2.collection = cv.collection
ORDER BY a3.mtime DESC, acc2.artefact ASC
LIMIT 1
)
AND cv.collection IN (' . join(',', array_fill(0, count($collids), '?')) . ')
',
$collids
);
}
// Now that we've retrieved comments counts & last comment data for each collection/view
// pop it into the data set
$fields = array('lastcommentviewid', 'lastcommenttime', 'commentauthor', 'commentauthorname', 'commenttext', 'commentid', 'commentcount');
foreach ($result->data as &$v) {
if (isset($commentdata[$v['id']])) {
$fill = false;
if ($v['collid']) {
if (isset($collectioncommentdata[$v['collid']])) {
$fill = $collectioncommentdata[$v['collid']];
}
}
else {
if (isset($viewcommentdata[$v['viewid']])) {
$fill = $viewcommentdata[$v['viewid']];
}
}
if ($fill) {
foreach ($fields as $f) {
$v[$f] = $commentdata[$v['id']]->$f;
$v[$f] = $fill->$f;
}
}
}
......@@ -6385,6 +6503,11 @@ function view_group_submission_form($view, $tutorgroupdata, $returnto=null) {
'class' => 'text-inline',
'value' => '',
),
'options' => array(
'type' => 'select',
'collapseifoneoption' => false,
'options' => $options,
),
'text2' => array(
'type' => 'html',
'class' => 'prm',
......
......@@ -657,13 +657,14 @@ EOD;
/**
* A fixture to set up page & collection permissions. Currently it only supports setting a blanket permission of
* "public", "loggedin", "friends", or "private".
* "public", "loggedin", "friends", or "private", and allowcomments & approvecomments
*
* Example:
* Given the following "permissions" exist:
* | title | accesstype
* | Page 1 | loggedin
* | Collection 1 | public
* | title | accesstype | accessname | allowcomments |
* | Page 1 | loggedin | loggedin | 1 |
* | Collection 1 | public | public | 1 |
* | Page 2 | user | userA | 0 |
* @param unknown $record
* @throws SystemException
*/
......@@ -695,13 +696,28 @@ EOD;
$accesslist = array();
}
else {
switch ($record['accesstype']) {
case 'user':
$ids = get_records_sql_array('SELECT id FROM {usr} WHERE LOWER(TRIM(username)) = ?', array(strtolower(trim($record['accessname']))));
if (!$ids || count($ids) > 1) {
throw new SystemException("Invalid access user '" . $record['accessname'] . "'. The username does not exist or duplicated");
}
$id = $ids[0]->id;
$type = 'user';
break;
case 'public':
case 'friends':
case 'loggedin':
$type = $id = $record['accesstype'];
break;
}
// TODO: This only supports one access record at a time per page
$accesslist = array(
array(
'startdate' => null,
'stopdate' => null,
'type' => $record['accesstype'],
'id' => $record['accesstype'],
'type' => $type,
'id' => $id,
)
);
}
......@@ -709,15 +725,13 @@ EOD;
'startdate' => null,
'stopdate' => null,
'template' => 0,
'retainview' => 0,
'allowcomments' => 0,
'approvecomments' => 1,
'retainview' => (isset($record['allowcomments']) ? $record['allowcomments'] : 0),
'allowcomments' => (isset($record['allowcomments']) ? $record['allowcomments'] : 1),
'approvecomments' => (isset($record['allowcomments']) ? $record['allowcomments'] : 1),
'accesslist' => $accesslist,
);
require_once('view.php');
var_dump($viewconfig);
var_dump($viewids);
View::update_view_access($viewconfig, $viewids);
}
}
\ No newline at end of file
......@@ -123,7 +123,10 @@ class BehatDataGenerators extends BehatBase {
'datagenerator' => 'permission',
'available' => array(
'title' => 'text',
'accesstype' => 'text',
'accesstype' => 'text',
'accessname' => 'text',
'allowcomments' => 'bool',
'approvecomments' => 'bool',
),
'required' => array('title', 'accesstype'),
),
......
{foreach from=$views item=view}
<tr class="{cycle values='r0,r1'}">
<td class="sharedpages">
<h3 class="title"><a href="{$view.fullurl}">{$view.title|str_shorten_text:65:true}</a></h3>
<h3 class="title"><a href="{$view.fullurl}">{$view.title|str_shorten_text:65:true}</a>{if $view.collid} ({str tag=nviews section=view arg1=$view.numpages}){/if}</h3>
{if $view.sharedby}
<div class="groupdate">
{if $view.group}
......@@ -25,7 +25,7 @@
<td class="lastcomment">
{if $view.commenttext}
<div class="comment">
<a href="{$WWWROOT}view/view.php?id={$view.id}&showcomment={$view.commentid}" title="{str tag=viewcomment section=artefact.comment}">{$view.commenttext|str_shorten_html:40:true|strip_tags|safe}</a>
<a href="{$WWWROOT}view/view.php?id={$view.lastcommentviewid}&showcomment={$view.commentid}" title="{str tag=viewcomment section=artefact.comment}">{$view.commenttext|str_shorten_html:40:true|strip_tags|safe}</a>
</div>
<span class="postedon metadata text-block mbm">{$view.lastcommenttime|strtotime|format_date:'strftimerecentyear'}</span>
{if $view.commentauthor}
......
@javascript @core @core_view @core_portfolio @aaron
Feature: The "Portfolio -> Shared with me" screen
In order to be able to see the Pages & Collections that have been shared with me
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Password1 | test01@example.com | Pete | Mc | mahara | internal | member |
| userB | Password1 | test02@example.com | Son | Nguyen | mahara | internal | member |
And the following "pages" exist:
| title | description| ownertype | ownername |
| P1A | page P1A | user | userA |
| P1B | page P1B | user | userA |
| P2 | page P2 | user | userA |
And the following "collections" exist:
| title | description| ownertype | ownername | pages |
| C1 | collection C1 | user | userA | P1A, P1B |
And the following "permissions" exist:
| title | accesstype | accessname | allowcomments |
| C1 | user | userB | 1 |
| P2 | user | userB | 1 |
Scenario: Testing that views & collections are collated properly
# Putting some comments on the pages
Given I log in as "userA" with password "Password1"
And I choose "Pages" in "Portfolio"
And I follow "P1A"
And I follow "Add comment"
And I fill in "I am on P1A" in WYSIWYG editor "add_feedback_form_message_ifr"
And I press "Comment"
And I choose "Pages" in "Portfolio"
And I follow "P1B"
And I follow "Add comment"
And I fill in "I am on P1B" in WYSIWYG editor "add_feedback_form_message_ifr"
And I press "Comment"
And I choose "Pages" in "Portfolio"
And I follow "P2"
And I follow "Add comment"
And I fill in "I am on P2" in WYSIWYG editor "add_feedback_form_message_ifr"
And I press "Comment"
When I log out
And I log in as "userB" with password "Password1"
And I choose "Shared with me" in "Portfolio"
Then I should see "page P2"
# I should see collections & individual pages
And I should see "I am on P2"
And I should see "C1 (2 pages)"
# I should not see pages in collections
And I should not see "page P1B"
# I should see the latest comment from C1 only
And I should see "I am on P1B"
And I should not see "I am on P1A"
And I should see "I am on P2"
Markdown is supported
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