Skip to content

Commit

Permalink
MDL-75664 mod_data: Approval status in database entries
Browse files Browse the repository at this point in the history
* Add approval status in the default template.
* Change the language string for unapproved entries.
  • Loading branch information
Laurent David committed Oct 17, 2022
1 parent 3bc792b commit e861d7b
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mod/data/classes/external.php
Expand Up @@ -527,7 +527,7 @@ public static function get_entry($entryid, $returncontents = false) {

// Check correct record entry. Group check was done before.
if (!data_can_view_record($database, $record, $record->groupid, $canmanageentries)) {
throw new moodle_exception('notapproved', 'data');
throw new moodle_exception('notapprovederror', 'data');
}

$related = array('context' => $context, 'database' => $database, 'user' => null);
Expand Down
2 changes: 1 addition & 1 deletion mod/data/classes/template.php
Expand Up @@ -605,7 +605,7 @@ protected function get_tag_approvalstatus_replacement(stdClass $entry, bool $can
if (!$this->instance->approval) {
return '';
}
return ($entry->approved) ? get_string('approved', 'data') : get_string('notapproved', 'data');
return ($entry->approved) ? '' : html_writer::div(get_string('notapproved', 'data'), 'mod-data-approval-status-badge');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion mod/data/lang/en/data.php
Expand Up @@ -300,7 +300,8 @@
$string['nomaximum'] = 'No maximum';
$string['nopreviewavailable'] = 'No preview available for {$a}';
$string['norecords'] = 'No entries yet';
$string['notapproved'] = 'Entry is not approved yet.';
$string['notapproved'] = 'Pending approval';
$string['notapprovederror'] = 'Entry is not approved yet.';
$string['notinjectivemap'] = 'Not an injective map';
$string['notopenyet'] = 'Sorry, this activity is not available until {$a}';
$string['number'] = 'Number';
Expand Down
2 changes: 1 addition & 1 deletion mod/data/lib.php
Expand Up @@ -3637,7 +3637,7 @@ function data_comment_validate($comment_param) {

//check if approved
if ($data->approval and !$record->approved and !data_isowner($record) and !has_capability('mod/data:approve', $context)) {
throw new comment_exception('notapproved', 'data');
throw new comment_exception('notapprovederror', 'data');
}

// group access
Expand Down
5 changes: 4 additions & 1 deletion mod/data/preset/imagegallery/listtemplate.html
Expand Up @@ -9,7 +9,10 @@
<a href="##moreurl##" class="stretched-link"></a>
</div>
<div class="d-flex align-items-start">
<div class="card-footer border-0 bg-white ml-auto" style="position: relative;">##actionsmenu##</div>
<div class="card-footer border-0 bg-white ml-auto d-flex" style="position: relative;">
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div>##actionsmenu##</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion mod/data/preset/imagegallery/singletemplate.html
@@ -1,7 +1,8 @@
<div class="imagegallery-single">
<div class="d-flex">
<h3 class="card-title">[[title]]</h3>
<div class="ml-auto">##actionsmenu##</div>
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div class="my-auto">##actionsmenu##</div>
</div>
<div class="imagegallery-single-body">
<div class="row">
Expand Down
3 changes: 2 additions & 1 deletion mod/data/preset/journal/listtemplate.html
Expand Up @@ -2,7 +2,8 @@
<div class="card-body">
<div class="d-flex">
<h3 class="card-title">[[Title]]</h3>
<div class="ml-auto">##actionsmenu##</div>
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div class="my-auto">##actionsmenu##</div>
</div>
<div class="card-text truncate-overflow mb-4">[[Content]]</div>
<p class="card-text">##userpicture## ##user##</p>
Expand Down
3 changes: 2 additions & 1 deletion mod/data/preset/journal/singletemplate.html
@@ -1,7 +1,8 @@
<div class="journal-single my-5">
<div class="d-flex">
<h3 class="card-title">[[Title]]</h3>
<div class="ml-auto">##actionsmenu##</div>
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div class="my-auto">##actionsmenu##</div>
</div>
<div class="journal-single-body my-5">
<div class="row">
Expand Down
11 changes: 7 additions & 4 deletions mod/data/preset/proposals/listtemplate.html
Expand Up @@ -2,14 +2,17 @@
<div class="card-header" role="tab" id="entry-##id##">
<div>
<div class="row align-middle">
<div class="col-4 col-sm-7 my-auto">
<div class="col-4 my-auto">
<a data-toggle="collapse" data-parent="#proposals-list" href="#collapseentry-##id##" aria-expanded="true" aria-controls="collapseentry-##id##" class="d-block">
<i class="fa fa-chevron-down"></i> [[Title]]
</a>
</div>
<div class="col-3 col-sm-2 push my-auto">[[Status]]</div>
<div class="col-4 col-sm-2 my-auto">##userpicture## ##user##</div>
<div class="ml-auto">##actionsmenu##</div>
<div class="col-3 push my-auto">[[Status]]</div>
<div class="col-2 my-auto">##userpicture## ##user##</div>
<div class="col-3 d-flex justify-content-end">
<div class="my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div class="ml-auto my-auto">##actionsmenu##</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion mod/data/preset/proposals/singletemplate.html
@@ -1,7 +1,8 @@
<div class="proposals-single my-5">
<div class="d-flex">
<h3 class="card-title">[[Title]]</h3>
<div class="ml-auto">##actionsmenu##</div>
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div class="my-auto">##actionsmenu##</div>
</div>
<div class="proposals-single-body">
<div class="row my-3">
Expand Down
8 changes: 6 additions & 2 deletions mod/data/styles.css
Expand Up @@ -116,8 +116,12 @@
text-align: right;
}

.mod-data-default-template.notapproved {
background-color: #fcc;
#page-mod-data-view .notapproved {
background-color: #fff3cd;
color: #856404;
border-radius: 0.5em;
padding: 0.5em 1em;
gap: 1em;
}

#page-mod-data-templates td.save_template,
Expand Down
3 changes: 2 additions & 1 deletion mod/data/templates/defaulttemplate_listtemplate.mustache
Expand Up @@ -35,7 +35,8 @@
}}
<div class="defaulttemplate-listentry my-5 p-5 card">
<div class="d-flex">
<div class="ml-auto">##actionsmenu##</div>
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div>##actionsmenu##</div>
</div>
<div class="defaulttemplate-list-body">
{{#fields}}
Expand Down
5 changes: 3 additions & 2 deletions mod/data/templates/defaulttemplate_singletemplate.mustache
Expand Up @@ -34,8 +34,9 @@
}
}}
<div id="defaulttemplate-single" class="my-5">
<div class="d-flex">
<div class="ml-auto mt-n6">##actionsmenu##</div>
<div class="d-flex mt-n6">
<div class="ml-auto my-auto ##approvalstatusclass##">##approvalstatus##</div>
<div>##actionsmenu##</div>
</div>
<div class="defaulttemplate-single-body my-5">
<div class="mt-4">
Expand Down
50 changes: 50 additions & 0 deletions mod/data/tests/behat/entry_approval.feature
@@ -0,0 +1,50 @@
@mod @mod_data
Feature: User can see the entry approval status on the single view and list view
in the default template.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber | approval |
| data | Test database name | Database intro | C1 | data1 | 1 |
And the following "mod_data > fields" exist:
| database | type | name | description |
| data1 | text | field1 | Test field description |
| data1 | text | field2 | Test field 2 description |
And the following "mod_data > templates" exist:
| database | name |
| data1 | singletemplate |
| data1 | listtemplate |
| data1 | addtemplate |
| data1 | asearchtemplate |
| data1 | rsstemplate |
And the following "mod_data > entries" exist:
| database | user | field1 | field2 |
| data1 | student1 | Student entry 1 | Some student content 1 |
| data1 | teacher1 | Teacher entry 1 | Some teacher content 1 |

@javascript
Scenario Outline: The approval status is displayed in the single view and list view next to the action menu
# List view.
Given I am on the "Test database name" "data activity" page logged in as <user>
Then I should see "Pending approval" in the "region-main" "region"
# Single view.
And I select "Single view" from the "jump" singleselect
And I should see "Pending approval" in the "region-main" "region"
And I click on "2" "link" in the ".pagination" "css_element"
And I should not see "Pending approval" in the "region-main" "region"
And I should not see "Approved" in the "region-main" "region"
Examples:
| user |
| student1 |
| teacher1 |
4 changes: 2 additions & 2 deletions mod/data/tests/externallib_test.php
Expand Up @@ -555,7 +555,7 @@ public function test_get_entries() {
$result = mod_data_external::get_entries($this->database->id);
$result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(4, $result['entries']); // I can see my entry not approved yet.
$this->assertCount(4, $result['entries']); // I can see my entry is pending approval.
$this->assertEquals(4, $result['totalcount']);

// Now try with the user in the second group that must see only two entries (his group entry and the one without group).
Expand Down Expand Up @@ -727,7 +727,7 @@ public function test_get_entry_separated_groups() {
$result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($entry21, $result['entry']['id']);

// Now, try to get an entry not approved yet.
// Now, try to get a pending approval.
$this->setUser($this->student1);
$this->expectException('moodle_exception');
$result = mod_data_external::get_entry($entry13);
Expand Down
8 changes: 4 additions & 4 deletions mod/data/tests/template_test.php
Expand Up @@ -294,14 +294,14 @@ public function parse_entries_provider(): array {
],
'Teacher approvalstatus tag approved entry' => [
'templatecontent' => 'Some ##approvalstatus## tag',
'expected' => '|Some Approved tag|',
'expected' => '|Some tag|', // We do not display the approval status anymore.
'rolename' => 'editingteacher',
'enableexport' => false,
'approved' => true,
],
'Teacher approvalstatus tag disapproved entry' => [
'templatecontent' => 'Some ##approvalstatus## tag',
'expected' => '|Some .*not approved.* tag|',
'expected' => '|Some .*Pending approval.* tag|',
'rolename' => 'editingteacher',
'enableexport' => false,
'approved' => false,
Expand Down Expand Up @@ -590,14 +590,14 @@ public function parse_entries_provider(): array {
],
'Student approvalstatus tag approved entry' => [
'templatecontent' => 'Some ##approvalstatus## tag',
'expected' => '|Some Approved tag|',
'expected' => '|Some tag|',
'rolename' => 'student',
'enableexport' => false,
'approved' => true,
],
'Student approvalstatus tag disapproved entry' => [
'templatecontent' => 'Some ##approvalstatus## tag',
'expected' => '|Some .*not approved.* tag|',
'expected' => '|Some .*Pending approval.* tag|',
'rolename' => 'student',
'enableexport' => false,
'approved' => false,
Expand Down
2 changes: 1 addition & 1 deletion mod/data/view.php
Expand Up @@ -250,7 +250,7 @@

// Detect entries not approved yet and show hint instead of not found error.
if ($record and !data_can_view_record($data, $record, $currentgroup, $canmanageentries)) {
throw new \moodle_exception('notapproved', 'data');
throw new \moodle_exception('notapprovederror', 'data');
}

// Do we need to show a link to the RSS feed for the records?
Expand Down

0 comments on commit e861d7b

Please sign in to comment.