Skip to content

Commit

Permalink
OU Blog: Automated read-only feature #82135
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-platts authored and sammarshallou committed Sep 22, 2015
1 parent 67df736 commit c6af2a4
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 13 deletions.
4 changes: 3 additions & 1 deletion backup/moodle2/backup_oublog_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected function define_structure() {
'maxbytes', 'maxattachments', 'maxvisibility', 'global', 'views',
'completionposts', 'completioncomments', 'reportingemail', 'displayname',
'statblockon', 'allowimport', 'introonpost', 'tags', 'assessed',
'assesstimestart', 'assesstimefinish', 'scale', 'grading', 'restricttags'));
'assesstimestart', 'assesstimefinish', 'scale', 'grading', 'restricttags',
'postfrom', 'postuntil', 'commentfrom', 'commentuntil'
));
$instances = new backup_nested_element('instances');

$instance = new backup_nested_element('instance', array('id'), array(
Expand Down
22 changes: 22 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,26 @@
'manager' => CAP_ALLOW
)
),

'mod/oublog:ignorepostperiod' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),

'mod/oublog:ignorecommentperiod' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
);
6 changes: 5 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/oublog/db" VERSION="20140725" COMMENT="XMLDB file for Moodle mod/oublog"
<XMLDB PATH="mod/oublog/db" VERSION="20150806" COMMENT="XMLDB file for Moodle mod/oublog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -34,6 +34,10 @@
<FIELD NAME="scale" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="grading" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="restricttags" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="postfrom" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Posting allowed from"/>
<FIELD NAME="postuntil" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Posting allowed until"/>
<FIELD NAME="commentfrom" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Comments allowed from"/>
<FIELD NAME="commentuntil" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Commenting allowed until"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
42 changes: 42 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,47 @@ function xmldb_oublog_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2014122400, 'oublog');
}

if ($oldversion < 2015090800) {

// Define field postfrom to be added to oublog.
$table = new xmldb_table('oublog');
$field = new xmldb_field('postfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'restricttags');

// Conditionally launch add field postfrom.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Define field postuntil to be added to oublog.
$table = new xmldb_table('oublog');
$field = new xmldb_field('postuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'postfrom');

// Conditionally launch add field postuntil.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Define field commentfrom to be added to oublog.
$table = new xmldb_table('oublog');
$field = new xmldb_field('commentfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'postuntil');

// Conditionally launch add field commentfrom.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Define field commentuntil to be added to oublog.
$table = new xmldb_table('oublog');
$field = new xmldb_field('commentuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'commentfrom');

// Conditionally launch add field commentuntil.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Oublog savepoint reached.
upgrade_mod_savepoint(true, 2015090800, 'oublog');
}

return true;
}
132 changes: 132 additions & 0 deletions internaldoc/testcase.readonlytime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
This script describes steps to test the read-only facility from a user
perspective. It is intended to cover most of the UI and features.

NOTE: In this test case, the word 'blog' always refers to the OU blog.

The test steps in this script follow on from each other and aren't independent.


Initial setup
=============

This test case requires:

- one test user (US1) with the Student role.
- one test user (admin) with the admin or manager role.

Test course (admin must have permissions to create/configure activities)

The test server must have debugging set to DEVELOPER level and to display
errors; during all parts of the test script, there should be no debugging
warnings.


POS Posting time limiting
=========================

POS01 / admin
In your test course, create a blog called POS01-RO,
this should have the 'Posting only allowed from' option under 'Contribution time period'
set to a date in the past and enabled.
Select 'Save and display'.
- Verify no messages displayed above 'New post' button.

POS02 / admin
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Change 'Posting only allowed from' to a date in the future.
Select 'Save and display'.
- Verify message informing that students will not be able to post until the date,
(but you can) is shown above 'New post' button.
- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format).

POS03 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that creating post is not available until date entered previously is shown.
- Verify 'New post button' is not shown.

POS04 / admin (change)
Enter the test course and select link to POS01-RO blog.
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Change 'Posting only allowed until' to enabled and make a date in future (after posting from date).
Select 'Save and display'.
- Verify message informing that students will not be able to post until the date,
(but you can) is shown above 'New post' button.
- Verify message informing that students will not be able to post after the second date,
(but you can) is shown above 'New post' button.
- Verify dates match those entered in settings form (dd/mm/yy, hh:mm format).

POS05 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that creating post is not available until date entered previously is shown.
- Verify message informing that creating post will only be available until date entered previously is shown.
- Verify 'New post button' is not shown.

POS06 / admin (change)
Enter the test course and select link to POS01-RO blog.
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Disable 'Posting only allowed from'.
Change 'Posting only allowed until' to a date in the past.
Select 'Save and display'.
- Verify message informing that students are no longer be able to post after date,
(but you can) is shown above 'New post' button.
- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format).

POS07 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that creating post is not available as after date entered previously is shown.
- Verify 'New post button' is not shown.

COM Comment time limiting
=========================

COM01 / admin
Enter the test course and select link to POS01-RO blog.
Select the 'New post' button and add a new post to the blog.
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Disable 'Posting only allowed until'.
Enable 'Commenting only allowed from' and set to a date in the future.
Select 'Save and display'.
- Verify message informing that students will not be able to comment on posts until the date,
(but you can) is shown above 'New post' button.
- Verify 'Add your comment' link is shown against the new post.

COM02 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that you are not able to comment on posts until the date,
is shown above 'New post' button.
- Verify 'Add your comment' link is not shown against the new post.

COM03 / admin (change)
Enter the test course and select link to POS01-RO blog.
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Disable 'Commenting only allowed from'.
Change 'Commenting only allowed until' to a date in the past.
Select 'Save and display'.
- Verify message informing that students are no longer be able to comment on posts as past date,
(but you can) is shown above 'New post' button.
- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format).
- Verify 'Add your comment' link is shown against the new post.

COM04 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that you are not able to comment on posts as past date,
is shown above 'New post' button.
- Verify 'Add your comment' link is not shown against the new post.

COM05 / admin (change)
Enter the test course and select link to POS01-RO blog.
Select 'Edit settings' from 'OU Blog administration' 'Administration' block.
Change 'Commenting only allowed until' to a date in the future.
Select 'Save and display'.
- Verify message informing that students will not be able to comment on posts after date,
(but you can) is shown above 'New post' button.
- Verify date matches that entered in settings form (dd/mm/yy, hh:mm format).
- Verify 'Add your comment' link is shown against the new post.

COM06 / student (change)
Enter the test course and select link to POS01-RO blog.
- Verify message informing that you will not able to comment on posts after date,
is shown above 'New post' button.
- Verify 'Add your comment' link is shown against the new post.

End test.
28 changes: 28 additions & 0 deletions lang/en/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@
$string['oublog:exportownpost'] = 'Export own post';
$string['oublog:exportpost'] = 'Export post';
$string['oublog:exportposts'] = 'Export posts';
$string['oublog:ignorepostperiod'] = 'Ignore post time period';
$string['oublog:ignorecommentperiod'] = 'Ignore comment time period';

$string['advancedoptions'] = 'Advanced options';
$string['limits'] = 'Contribution time period';
$string['postfrom'] = 'Posting only allowed from';
$string['postuntil'] = 'Posting only allowed until';
$string['commentfrom'] = 'Commenting only allowed from';
$string['commentuntil'] = 'Commenting only allowed until';
$string['beforestartpost'] = 'You cannot create posts at this time. Post creation is available from {$a}.';
$string['beforestartpostcapable'] = 'Students cannot create their own posts until {$a}.
<br/> You have access to create posts before this time.';
$string['beforeendpost'] = 'You can only create posts until {$a}.';
$string['beforeendpostcapable'] = 'Students are able to create their own posts until {$a}.
<br/> You have access to create posts after this time.';
$string['afterendpost'] = 'You cannot create posts at this time. Post creation ended on {$a}.';
$string['afterendpostcapable'] = 'Students were able to create their own posts until {$a}.
<br/> You have access to create posts after this time.';
$string['beforestartcomment'] = 'You cannot comment on posts at this time. Commenting is available from {$a}.';
$string['beforestartcommentcapable'] = 'Students cannot comment on posts until {$a}.
<br/> You have access to comment before this time.';
$string['beforeendcomment'] = 'You can only comment on posts until {$a}.';
$string['beforeendcommentcapable'] = 'Students are able to comment on posts until {$a}.
<br/> You have access to comment after this time.';
$string['afterendcomment'] = 'You cannot comment on posts at this time. Commenting ended on {$a}.';
$string['afterendcommentcapable'] = 'Students were able to comment on posts until {$a}.
<br/> You have access to comment after this time.';

$string['mustprovidepost'] = 'Must provide postid';
$string['newpost'] = 'New {$a} post';
$string['removeblogs'] = 'Remove all blog entries';
Expand Down
36 changes: 34 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ function oublog_check_view_permissions($oublog, $context, $cm=null) {
}
}

/**
* Checks if user can post to the blog depending on time limits
* @param object $oublog
* @param context $context
* @return bool True if can post
*/
function oublog_can_post_now($oublog, $context) {
if (($oublog->postfrom == 0 || $oublog->postfrom <= time()) &&
($oublog->postuntil == 0 || $oublog->postuntil > time())) {
// Within time limits.
return true;
}
if ($oublog->global && $context->contextlevel != CONTEXT_SYSTEM) {
// Global blog override and check at system context.
$context = context_system::instance();
}
return has_capability('mod/oublog:ignorepostperiod', $context);
}

/**
* Determines whether the user can make a post to the given blog.
* @param $oublog Blog object
Expand Down Expand Up @@ -217,10 +236,12 @@ function oublog_can_post($oublog, $bloguserid=0, $cm=null) {
* @param $cm Course-module (null if personal blog)
* @param $oublog Blog object
* @param $post Post object
* @param bool $ignoretime True to ignore any comment time limits
* @return bool True if user is allowed to make comments
*/
function oublog_can_comment($cm, $oublog, $post) {
function oublog_can_comment($cm, $oublog, $post, $ignoretime = false) {
global $USER;

if ($oublog->global) {
// Just need the 'contributepersonal' permission at system level, OR
// if you are not logged in but the blog allows public comments.
Expand Down Expand Up @@ -263,11 +284,22 @@ function oublog_can_comment($cm, $oublog, $post) {
// make this make sense, or some other changes.
}

// Test comment time period.
$timeok = (($oublog->commentfrom == 0 || $oublog->commentfrom <= time()) &&
($oublog->commentuntil == 0 || $oublog->commentuntil > time()));
if ($ignoretime) {
$timeok = true;
}
if (!$timeok && has_capability('mod/oublog:ignorecommentperiod',
$oublog->global ? context_system::instance() : context_module::instance($cm->id))) {
$timeok = true;
}

// If the blog allows comments, this post must allow comments and either
// it allows public comments or you're logged in (and not guest)
return $blogok && $post->allowcomments &&
($post->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC ||
(isloggedin() && !isguestuser()));
(isloggedin() && !isguestuser())) && $timeok;
}

/**
Expand Down
Loading

0 comments on commit c6af2a4

Please sign in to comment.