Commit c541ba8c authored by Robert Lyon's avatar Robert Lyon Committed by Jono Mingard
Browse files

Bug 1201174: Correctly saving access rules for allowing comments



When turning off allowcomments page-wise and adding them per 'Share
with' options

Change-Id: Ic367fa89a04fa91c655c3f42005685181b948f78
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent b71436f8
......@@ -992,7 +992,7 @@ class View {
// Use set_access() on the first view to get a hopefully consistent
// and complete representation of the access list
$firstview = new View($viewids[0]);
$fullaccesslist = $firstview->set_access($config['accesslist'], $viewids);
$fullaccesslist = $firstview->set_access($config['accesslist'], $viewids, $config['allowcomments']);
// Copy the first view's access records to all the other views
$firstview->copy_access($viewids);
......@@ -1244,7 +1244,18 @@ class View {
return false;
}
public function set_access($accessdata, $viewids = null) {
/**
* Set the view access rules
* @param $accessdata array For each view access row
Can contain id, type, startdate, stopdate, allowcomments, approvecomments
* @param $viewids array Contains ids of the views getting the access rules
* @param $allowcomments bool Holding the view wide allowcomments option
Needed when changing this and saving page at same time
as the views are not saved at this point.
*
* @return $accessdata_added array The added access rows
*/
public function set_access($accessdata, $viewids = null, $allowcomments = true) {
global $USER;
require_once('activity.php');
require_once('group.php');
......@@ -1280,7 +1291,8 @@ class View {
if (!empty($item['startdate']) && $item['startdate'] < $time) {
unset($item['startdate']);
}
if ($this->get('allowcomments')) {
if ($allowcomments) {
unset($item['allowcomments']);
unset($item['approvecomments']);
}
......@@ -5848,37 +5860,39 @@ class View {
$cid = $this->collection_id();
$ctoken = $cid ? get_cookie('caccess:'.$cid) : null;
foreach ($access as $a) {
if ($a->accesstype == 'public') {
if (!$publicviews && (!$publicprofiles || $this->type != 'profile')) {
if ($access) {
foreach ($access as $a) {
if ($a->accesstype == 'public') {
if (!$publicviews && (!$publicprofiles || $this->type != 'profile')) {
continue;
}
}
else if ($a->token && $a->token != $mnettoken
&& (!$publicviews || ($a->token != $usertoken && $a->token != $ctoken))) {
continue;
}
}
else if ($a->token && $a->token != $mnettoken
&& (!$publicviews || ($a->token != $usertoken && $a->token != $ctoken))) {
continue;
}
else if (!$user->is_logged_in()) {
continue;
}
else if ($a->accesstype == 'friends') {
$owner = $this->get('owner');
if (!get_field_sql('
SELECT COUNT(*) FROM {usr_friend} f WHERE (usr1=? AND usr2=?) OR (usr1=? AND usr2=?)',
array($owner, $userid, $userid, $owner)
)) {
else if (!$user->is_logged_in()) {
continue;
}
}
else if ($a->accesstype == 'friends') {
$owner = $this->get('owner');
if (!get_field_sql('
SELECT COUNT(*) FROM {usr_friend} f WHERE (usr1=? AND usr2=?) OR (usr1=? AND usr2=?)',
array($owner, $userid, $userid, $owner)
)) {
continue;
}
}
$objectionable = $this->is_objectionable();
if ($a->allowcomments && (($objectionable && ($user->get('admin')
|| $user->is_institutional_admin()) || !$objectionable))) {
$allowcomments = $allowcomments || $a->allowcomments;
$approvecomments = $approvecomments && $a->approvecomments;
}
if (!$approvecomments) {
return true;
$objectionable = $this->is_objectionable();
if ($a->allowcomments && (($objectionable && ($user->get('admin')
|| $user->is_institutional_admin()) || !$objectionable))) {
$allowcomments = $allowcomments || $a->allowcomments;
$approvecomments = $approvecomments && $a->approvecomments;
}
if (!$approvecomments) {
return true;
}
}
}
......
......@@ -12,8 +12,8 @@
<th class="text-center">{{str tag=From}}</th>
<th class="text-center">{{str tag=To}}</th>
{{if $viewtype !== "profile" }}
<th class="text-center"><div class="th-shared-wrap"><span class="th-shared-heading">{{str tag=comments section=view}}</span> <span class="th-shared-title">{{str tag=allow section=view}}</span></div></th>
<th class="text-center"><span class="sr-only">{{str tag=Comments}}</span> <span class="th-shared-title">{{str tag=moderate section=view}}</span></th>
<th class="text-center commentcolumn"><div class="th-shared-wrap"><span class="th-shared-heading">{{str tag=comments section=view}}</span> <span class="th-shared-title">{{str tag=allow section=view}}</span></div></th>
<th class="text-center commentcolumn"><span class="sr-only">{{str tag=Comments}}</span> <span class="th-shared-title">{{str tag=moderate section=view}}</span></th>
{{/if}}
</tr>
</thead>
......@@ -98,11 +98,11 @@
</div>
</td>
{% if (o.viewtype !== "profile") { %}
<td class="text-center tiny">
<input value="1" name="accesslist[{%=o.id%}][allowcomments]" class="allow-comments-checkbox checkbox js-hide-empty {% if (o.presets.empty) { %}hidden{% } %}" type="checkbox" {% if (o.presets.allowcomments == "0") { %}{% } else { %}checked{% } %} {% if (o.presets.locked) { %}disabled{% } %}>
<td class="text-center tiny commentcolumn">
<input value="1" name="accesslist[{%=o.id%}][allowcomments]" class="allow-comments-checkbox checkbox js-hide-empty {% if (o.presets.empty) { %}hidden{% } %}" type="checkbox" {% if (o.presets.allowcomments == "1") { %}checked{% } else { %}{% } %} {% if (o.presets.locked) { %}disabled{% } %}>
</td>
<td class="text-center tiny">
<input value="1" name="accesslist[{%=o.id%}][approvecomments]" class="moderate-comments-checkbox checkbox js-hide-empty {% if (o.presets.empty) { %}hidden{% } %}" type="checkbox" {% if (o.presets.approvecomments) { %}checked{% } %} {% if (o.presets.locked) { %}disabled{% } %}>
<td class="text-center tiny commentcolumn">
<input value="1" name="accesslist[{%=o.id%}][approvecomments]" class="moderate-comments-checkbox checkbox js-hide-empty {% if (o.presets.empty) { %}hidden{% } %}" type="checkbox" {% if (o.presets.approvecomments == "1" && o.presets.allowcomments == "1") { %}checked{% } else { %}{% } %} {% if (o.presets.locked) { %}disabled{% } %}>
</td>
{% } %}
......@@ -505,22 +505,29 @@ jQuery(function($) {
}
function attachCommentEvents(newrow) {
newrow.find('.allow-comments-checkbox').on('change', function() {
if ($('#editaccess_allowcomments').prop('checked') === true) {
// Hide the per row comment options
newrow.find('.commentcolumn').addClass('hidden');
}
var allowcommentsbox = newrow.find('.allow-comments-checkbox');
var moderatecommentsbox = newrow.find('.moderate-comments-checkbox');
// TODO: could probably use a function to eliminate the duplicate code between
// here and the change event handler
if (allowcommentsbox.prop('checked') == false) {
moderatecommentsbox.prop("disabled", true).prop("checked", false);
}
else {
moderatecommentsbox.prop('disabled', false);
}
allowcommentsbox.on('change', function() {
if ($(this).prop('checked') == false) {
newrow.find('.moderate-comments-checkbox').prop("disabled", true).prop("checked", false);
moderatecommentsbox.prop("disabled", true).prop("checked", false);
}
else {
newrow.find('.moderate-comments-checkbox').prop('disabled', false);
moderatecommentsbox.prop('disabled', false);
}
});
newrow.find('.allow-comments-checkbox').on('change', function() {
$('#editaccess_allowcomments').prop('checked', false);
});
newrow.find('.moderate-comments-checkbox').on('change', function() {
$('#editaccess_approvecomments').prop('checked', false);
});
}
var rows = $('#accesslistitems > tr'),
......@@ -529,14 +536,6 @@ jQuery(function($) {
renderAccessList(shareoptions);
setDatePicker($( ".js-date-picker > input" ));
$('#editaccess_allowcomments').on('change', function() {
$('.allow-comments-checkbox').prop('checked', true);
});
$('#editaccess_approvecomments').on('change', function() {
$('.moderate-comments-checkbox').prop('checked', true);
});
});
});
......
......@@ -268,19 +268,20 @@ function update_comment_options() {
if (allowcomments) {
removeElementClass($('editaccess_approvecomments'), 'hidden');
removeElementClass($('editaccess_approvecomments_container'), 'hidden');
forEach(getElementsByTagAndClassName(null, 'comments', 'accesslisttable'), function (elem) {
forEach(getElementsByTagAndClassName(null, 'commentcolumn', 'accesslisttable'), function (elem) {
addElementClass(elem, 'hidden');
});
}
else {
addElementClass($('editaccess_approvecomments_container'), 'hidden');
forEach(getElementsByTagAndClassName(null, 'comments', 'accesslisttable'), function (elem) {
forEach(getElementsByTagAndClassName(null, 'commentcolumn', 'accesslisttable'), function (elem) {
removeElementClass(elem, 'hidden');
});
}
}
addLoadEvent(function() {
connect('editaccess_allowcomments', 'onclick', update_comment_options);
update_comment_options();
});
EOF;
......
......@@ -4,17 +4,18 @@ Feature: Adding pages to a collection
As an admin I need pages
So I can add them to the collection
Background:
Given the following "pages" exist:
| title | description| ownertype | ownername |
| Testing page 1 | UserD's page 01 | user | admin |
| Testing page 2 | UserD's page 02 | user | admin |
| Testing page 3 | UserA's page 01 | user | admin |
Scenario: Creating a collection AND adding pages
# Log in as "Admin" user
Given I log in as "admin" with password "Kupuhipa1"
# Verifying log in was successful
And I should see "Admin User"
Given the following "pages" exist:
| title | description| ownertype | ownername |
| Testing page 1 | UserD's page 01 | user | admin |
| Testing page 2 | UserD's page 02 | user | admin |
| Testing page 3 | UserA's page 01 | user | admin |
# Create Test collection
And I choose "Collections" in "Portfolio"
And I follow "New collection"
......@@ -34,5 +35,6 @@ Scenario: Creating a collection AND adding pages
And I select "Last modified" from "Sort by:"
And I press "Search"
# Checking they are in the right order
And I wait "1" seconds
And "Testing page 1" "link" should appear before "Testing page 2" "link"
And "Testing page 2" "link" should appear before "Testing page 3" "link"
@javascript @core @share_comments
Feature: Added ID's for text blocks
In order for allow and moderate comments to save correctly
As an admin
I need to be able to save it once and not have to do it again in Edit Access screen
Scenario: Correctly saving access rules for allowing comments (Bug 1201174)
#Logging in and Creating a group
Given I log in as "admin" with password "Kupuhipa1"
Then I follow "Groups"
Then I should see "My groups"
When I follow "Create group"
Then I should see "Create group"
When I set the following fields to these values:
| editgroup_name | Test Group1 |
And I press "editgroup_submit"
Then I should see "Group saved successfully"
#Creating a page to share with group
When I follow "Portfolio"
Then I should see "Pages"
When I press "createview_submit"
Then I should see "No title"
When I set the following fields to these values:
| editview_title | Group page1 |
And I wait "5" seconds
Then I press "editview_submit"
Then I should see "Page saved successfully"
# Sharing Page
When I follow "Share page"
Then I should see "Edit access"
When I set the following fields to these values:
| accesslist[0][searchtype] | Test Group1 |
Then I follow "Advanced options"
And I set the following fields to these values:
|Allow comments | 0 |
Then I should see "Comments" in the "table#accesslisttable" "css_element"
When I check "accesslist[0][allowcomments]"
And I press "Save"
Then I should see "Share"
# Checking if checked option worked
When I click on "Edit access" in "Group page1" row
Then I should see "Edit access"
And the "accesslist[0][allowcomments]" checkbox should be checked
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