Skip to content

Commit

Permalink
MDL-63995 blocks: Remove unused capabilities and warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
danmarsden committed Mar 24, 2019
1 parent 3271c39 commit ef78cf8
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 64 deletions.
10 changes: 9 additions & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,16 @@ function user_can_edit() {
function user_can_addto($page) {
global $USER;

// List of formats this block supports.
$formats = $this->applicable_formats();

// The blocks in My Moodle are a special case and use a different capability.
if (!empty($USER->id)
&& $page->context->contextlevel == CONTEXT_USER // Page belongs to a user
&& $page->context->instanceid == $USER->id // Page belongs to this user
&& $page->pagetype == 'my-index') { // Ensure we are on the My Moodle page

// If the block cannot be displayed on /my it is ok if the myaddinstance capability is not defined.
$formats = $this->applicable_formats();
// Is 'my' explicitly forbidden?
// If 'all' has not been allowed, has 'my' been explicitly allowed?
if ((isset($formats['my']) && $formats['my'] == false)
Expand All @@ -601,6 +603,12 @@ function user_can_addto($page) {
&& has_capability('moodle/my:manageblocks', $page->context);
}
}
// Check if this is a block only used on /my.
unset($formats['my']);
if (empty($formats)) {
// Block can only be added to /my - return false.
return false;
}

$capability = 'block/' . $this->name() . ':addinstance';
if ($this->has_add_block_capability($page, $capability)
Expand Down
12 changes: 0 additions & 12 deletions blocks/myoverview/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,5 @@
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
),

'block/myoverview:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
1 change: 0 additions & 1 deletion blocks/myoverview/lang/en/block_myoverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
$string['inprogress'] = 'In progress';
$string['lastaccessed'] = 'Last accessed';
$string['list'] = 'List';
$string['myoverview:addinstance'] = 'Add a new course overview block';
$string['myoverview:myaddinstance'] = 'Add a new course overview block to Dashboard';
$string['past'] = 'Past';
$string['pluginname'] = 'Course overview';
Expand Down
5 changes: 5 additions & 0 deletions blocks/myoverview/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file describes API changes in the myoverview block code.

=== 3.7 ===

* The 'block/myoverview:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/myoverview/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019022600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018112800; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).
10 changes: 0 additions & 10 deletions blocks/recentlyaccessedcourses/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,5 @@
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
),

'block/recentlyaccessedcourses:addinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
*/
$string['pluginname'] = 'Recently accessed courses';
$string['privacy:metadata'] = 'The Recently accessed courses block does not store any personal data.';
$string['recentlyaccessedcourses:addinstance'] = 'Add a new Recently accessed courses block';
$string['recentlyaccessedcourses:myaddinstance'] = 'Add a new recently accessed courses block to Dashboard';
$string['nocourses'] = 'No recent courses';
5 changes: 5 additions & 0 deletions blocks/recentlyaccessedcourses/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file describes API changes in the recentlyaccesscourses block code.

=== 3.7 ===

* The 'block/recentlyaccesscourses:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/recentlyaccessedcourses/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019022600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018112800; // Requires this Moodle version.
$plugin->component = 'block_recentlyaccessedcourses'; // Full name of the plugin (used for diagnostics).
8 changes: 0 additions & 8 deletions blocks/recentlyaccesseditems/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,5 @@
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/recentlyaccesseditems:addinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
$string['privacy:metadata:timeaccess'] = 'The time when the user last accessed the item';
$string['privacy:metadata:userid'] = 'The ID of the user who accessed the item';
$string['privacy:recentlyaccesseditemspath'] = 'Recently accessed items';
$string['recentlyaccesseditems:addinstance'] = 'Add a new recently accessed items block';
$string['recentlyaccesseditems:myaddinstance'] = 'Add a new recently accessed items block to Dashboard';
5 changes: 5 additions & 0 deletions blocks/recentlyaccesseditems/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file describes API changes in the recentlyaccesseditems block code.

=== 3.7 ===

* The 'block/recentlyaccesseditems:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/recentlyaccesseditems/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018120301; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019022600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018112800; // Requires this Moodle version.
$plugin->component = 'block_recentlyaccesseditems'; // Full name of the plugin (used for diagnostics).
12 changes: 1 addition & 11 deletions blocks/starredcourses/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,5 @@
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
),

'block/starredcourses:addinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
)
);
1 change: 0 additions & 1 deletion blocks/starredcourses/lang/en/block_starredcourses.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@

$string['pluginname'] = 'Starred courses';
$string['privacy:metadata'] = 'The starred courses block does not store any personal data.';
$string['starredcourses:addinstance'] = 'Add a new starred courses block';
$string['starredcourses:myaddinstance'] = 'Add a new starred courses block to Dashboard';
$string['nocourses'] = 'No starred courses';
5 changes: 5 additions & 0 deletions blocks/starredcourses/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file describes API changes in the starredcourses block code.

=== 3.7 ===

* The 'block/starredcourses:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/starredcourses/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
*/
defined('MOODLE_INTERNAL') || die;

$plugin->version = 2018120300;
$plugin->version = 2019022600;
$plugin->requires = 2018112800;
$plugin->component = 'block_starredcourses';
12 changes: 0 additions & 12 deletions blocks/timeline/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,5 @@
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
),

'block/timeline:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
1 change: 0 additions & 1 deletion blocks/timeline/lang/en/block_timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
$string['ariaviewselectoroption'] = '{$a} sort option';
$string['duedate'] = 'Due date';
$string['morecourses'] = 'More courses';
$string['timeline:addinstance'] = 'Add a new timeline block';
$string['timeline:myaddinstance'] = 'Add a new timeline block to Dashboard';
$string['nocoursesinprogress'] = 'No in-progress courses';
$string['noevents'] = 'No upcoming activities due';
Expand Down
5 changes: 5 additions & 0 deletions blocks/timeline/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file describes API changes in the timeline block code.

=== 3.7 ===

* The 'block/timeline:addinstance' capability has been removed. It has never been used in code.
2 changes: 1 addition & 1 deletion blocks/timeline/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019022600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018112800; // Requires this Moodle version.
$plugin->component = 'block_timeline'; // Full name of the plugin (used for diagnostics).
3 changes: 3 additions & 0 deletions blocks/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
This files describes API changes in /blocks/* - activity modules,
information provided here is intended especially for developers.

=== 3.7 ===
* The block:addinstance capability is no longer required if the block can only be added to a dashboard.

=== 3.6 ===

* The timeline view from block_myoverview has been split out into block_timeline.
Expand Down

0 comments on commit ef78cf8

Please sign in to comment.