mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-51645 tool_lp: Rename the plan capabilities
This commit is contained in:
parent
3a4c71dc22
commit
53084abb75
10 changed files with 45 additions and 45 deletions
|
@ -1207,13 +1207,13 @@ class api {
|
|||
|
||||
// We can allow guest user to pass they will not have LP.
|
||||
if ($USER->id != $userid) {
|
||||
require_capability('tool/lp:planviewall', $context);
|
||||
require_capability('tool/lp:planview', $context);
|
||||
} else {
|
||||
require_capability('tool/lp:planviewown', $context);
|
||||
}
|
||||
|
||||
// Users that can manage plans can only see active and completed plans.
|
||||
if (!has_any_capability(array('tool/lp:planmanageall', 'tool/lp:planmanageown', 'tool/lp:plancreatedraft'), $context)) {
|
||||
if (!has_any_capability(array('tool/lp:planmanage', 'tool/lp:planmanageown', 'tool/lp:plancreateown'), $context)) {
|
||||
$select = ' AND status != :statusdraft';
|
||||
$params['statusdraft'] = plan::STATUS_DRAFT;
|
||||
}
|
||||
|
@ -1232,16 +1232,16 @@ class api {
|
|||
|
||||
$context = context_user::instance($record->userid);
|
||||
|
||||
$manageplans = has_capability('tool/lp:planmanageall', $context);
|
||||
$createdraft = has_capability('tool/lp:plancreatedraft', $context);
|
||||
$manageplans = has_capability('tool/lp:planmanage', $context);
|
||||
$createdraft = has_capability('tool/lp:plancreateown', $context);
|
||||
$manageownplan = has_capability('tool/lp:planmanageown', $context);
|
||||
|
||||
// Any of them is enough.
|
||||
if ($USER->id == $record->userid && !$manageplans && !$createdraft && !$manageownplan) {
|
||||
// Exception about plancreatedraft as it is the one that is closer to basic users.
|
||||
throw new required_capability_exception($context, 'tool/lp:plancreatedraft', 'nopermissions', '');
|
||||
// Exception about plancreateown as it is the one that is closer to basic users.
|
||||
throw new required_capability_exception($context, 'tool/lp:plancreateown', 'nopermissions', '');
|
||||
} else if ($USER->id != $record->userid && !$manageplans) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
|
||||
}
|
||||
|
||||
if (!isset($record->status)) {
|
||||
|
@ -1268,15 +1268,15 @@ class api {
|
|||
|
||||
$context = context_user::instance($record->userid);
|
||||
|
||||
$manageplans = has_capability('tool/lp:planmanageall', $context);
|
||||
$createdraft = has_capability('tool/lp:plancreatedraft', $context);
|
||||
$manageplans = has_capability('tool/lp:planmanage', $context);
|
||||
$createdraft = has_capability('tool/lp:plancreateown', $context);
|
||||
$manageownplan = has_capability('tool/lp:planmanageown', $context);
|
||||
|
||||
// Any of them is enough.
|
||||
if ($USER->id == $record->userid && !$manageplans && !$createdraft && !$manageownplan) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
|
||||
} else if (!$manageplans) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
|
||||
}
|
||||
|
||||
$plan = new plan($record->id);
|
||||
|
@ -1286,7 +1286,7 @@ class api {
|
|||
if (!$manageplans && !$manageownplan && $USER->id != $plan->get_usermodified()) {
|
||||
throw new \moodle_exception('erroreditingmodifiedplan', 'tool_lp');
|
||||
} else if (!$manageplans && $USER->id != $plan->get_userid()) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// If the user can only create drafts we don't allow them to set other status.
|
||||
|
@ -1313,14 +1313,14 @@ class api {
|
|||
if ($USER->id == $plan->get_userid()) {
|
||||
require_capability('tool/lp:planviewown', $context);
|
||||
} else {
|
||||
require_capability('tool/lp:planviewall', $context);
|
||||
require_capability('tool/lp:planview', $context);
|
||||
}
|
||||
|
||||
// We require any of these capabilities to retrieve draft plans.
|
||||
if ($plan->get_status() == plan::STATUS_DRAFT &&
|
||||
!has_any_capability(array('tool/lp:planmanageown', 'tool/lp:planmanageall', 'tool/lp:plancreatedraft'), $context)) {
|
||||
// Exception about plancreatedraft as it is the one that is closer to basic users.
|
||||
throw new required_capability_exception($context, 'tool/lp:plancreatedraft', 'nopermissions', '');
|
||||
!has_any_capability(array('tool/lp:planmanageown', 'tool/lp:planmanage', 'tool/lp:plancreateown'), $context)) {
|
||||
// Exception about plancreateown as it is the one that is closer to basic users.
|
||||
throw new required_capability_exception($context, 'tool/lp:plancreateown', 'nopermissions', '');
|
||||
}
|
||||
return $plan;
|
||||
}
|
||||
|
@ -1338,7 +1338,7 @@ class api {
|
|||
|
||||
$context = context_user::instance($plan->get_userid());
|
||||
|
||||
$manageplans = has_capability('tool/lp:planmanageall', $context);
|
||||
$manageplans = has_capability('tool/lp:planmanage', $context);
|
||||
$manageownplan = has_capability('tool/lp:planmanageown', $context);
|
||||
|
||||
if ($USER->id == $plan->get_userid() && $USER->id != $plan->get_usermodified() &&
|
||||
|
@ -1347,7 +1347,7 @@ class api {
|
|||
throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
|
||||
} else if ($USER->id != $plan->get_userid() && !$manageplans) {
|
||||
// Other users needs to have tool/lp:planmanage.
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
|
||||
}
|
||||
|
||||
return $plan->delete();
|
||||
|
|
|
@ -101,7 +101,7 @@ class plan extends persistent {
|
|||
$context = context_user::instance($userid);
|
||||
|
||||
// Not all users can edit all plans, the template should know about it.
|
||||
if (has_capability('tool/lp:planmanageall', $context) ||
|
||||
if (has_capability('tool/lp:planmanage', $context) ||
|
||||
has_capability('tool/lp:planmanageown', $context)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ $capabilities = array(
|
|||
),
|
||||
'clonepermissionsfrom' => 'moodle/block:view'
|
||||
),
|
||||
'tool/lp:plancreatedraft' => array(
|
||||
'tool/lp:plancreateown' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'contextlevel' => CONTEXT_USER,
|
||||
'archetypes' => array(
|
||||
),
|
||||
'clonepermissionsfrom' => 'moodle/site:config'
|
||||
),
|
||||
'tool/lp:planmanageall' => array(
|
||||
'tool/lp:planmanage' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => array(
|
||||
|
@ -81,7 +81,7 @@ $capabilities = array(
|
|||
),
|
||||
'clonepermissionsfrom' => 'moodle/site:config'
|
||||
),
|
||||
'tool/lp:planviewall' => array(
|
||||
'tool/lp:planview' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_USER,
|
||||
'archetypes' => array(
|
||||
|
|
|
@ -346,7 +346,7 @@ $functions = array(
|
|||
'classpath' => '',
|
||||
'description' => 'Creates a learning plan.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'tool/lp:planmanageall',
|
||||
'capabilities' => 'tool/lp:planmanage',
|
||||
),
|
||||
'tool_lp_update_plan' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
|
@ -354,7 +354,7 @@ $functions = array(
|
|||
'classpath' => '',
|
||||
'description' => 'Updates a learning plan.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'tool/lp:planmanageall',
|
||||
'capabilities' => 'tool/lp:planmanage',
|
||||
),
|
||||
'tool_lp_read_plan' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
|
@ -370,7 +370,7 @@ $functions = array(
|
|||
'classpath' => '',
|
||||
'description' => 'Delete a learning plan.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'tool/lp:planmanageall',
|
||||
'capabilities' => 'tool/lp:planmanage',
|
||||
),
|
||||
'tool_lp_data_for_plans_page' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
|
|
|
@ -55,12 +55,12 @@ $PAGE->set_pagelayout('admin');
|
|||
$PAGE->set_heading($pagetitle);
|
||||
$output = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
$manageplans = has_capability('tool/lp:planmanageall', $context);
|
||||
$owncapabilities = array('tool/lp:plancreatedraft', 'tool/lp:planmanageown');
|
||||
$manageplans = has_capability('tool/lp:planmanage', $context);
|
||||
$owncapabilities = array('tool/lp:plancreateown', 'tool/lp:planmanageown');
|
||||
if ($USER->id === $userid && !has_any_capability($owncapabilities, $context) && !$manageplans) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageown', 'nopermissions', '');
|
||||
} else if (!$manageplans) {
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanageall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planmanage', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// Passing the templates list to the form.
|
||||
|
|
|
@ -84,10 +84,10 @@ $string['lp:competencymanage'] = 'Manage competency frameworks';
|
|||
$string['lp:competencyread'] = 'View competency frameworks';
|
||||
$string['lp:coursecompetencymanage'] = 'Manage course competencies';
|
||||
$string['lp:coursecompetencyread'] = 'View course competencies';
|
||||
$string['lp:plancreatedraft'] = 'Create draft learning plans';
|
||||
$string['lp:planmanageall'] = 'Manage learning plans';
|
||||
$string['lp:plancreateown'] = 'Create own learning plans';
|
||||
$string['lp:planmanage'] = 'Manage learning plans';
|
||||
$string['lp:planmanageown'] = 'Manage own learning plans';
|
||||
$string['lp:planviewall'] = 'View all learning plans';
|
||||
$string['lp:planview'] = 'View all learning plans';
|
||||
$string['lp:planviewown'] = 'View own learning plans';
|
||||
$string['lp:templatemanage'] = 'Manage templates';
|
||||
$string['lp:templateread'] = 'View template';
|
||||
|
|
|
@ -60,7 +60,7 @@ function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $us
|
|||
global $USER;
|
||||
|
||||
$context = context_user::instance($USER->id);
|
||||
if (!$iscurrentuser && !has_capability('tool/lp:planviewall', $context)) {
|
||||
if (!$iscurrentuser && !has_capability('tool/lp:planview', $context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ if (!$user || !core_user::is_real_user($userid)) {
|
|||
throw new moodle_exception('invaliduser', 'error');
|
||||
}
|
||||
|
||||
if (!has_capability('tool/lp:planviewall', $context)) {
|
||||
if (!has_capability('tool/lp:planview', $context)) {
|
||||
if ($iscurrentuser) {
|
||||
require_capability('tool/lp:planviewown', $context);
|
||||
} else {
|
||||
throw new required_capability_exception($context, 'tool/lp:planviewall', 'nopermissions', '');
|
||||
throw new required_capability_exception($context, 'tool/lp:planview', 'nopermissions', '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,9 +99,9 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
// Reset all default authenticated users permissions.
|
||||
unassign_capability('tool/lp:competencymanage', $authrole->id);
|
||||
unassign_capability('tool/lp:competencyread', $authrole->id);
|
||||
unassign_capability('tool/lp:planmanageall', $authrole->id);
|
||||
unassign_capability('tool/lp:planmanage', $authrole->id);
|
||||
unassign_capability('tool/lp:planmanageown', $authrole->id);
|
||||
unassign_capability('tool/lp:planviewall', $authrole->id);
|
||||
unassign_capability('tool/lp:planview', $authrole->id);
|
||||
unassign_capability('tool/lp:templatemanage', $authrole->id);
|
||||
unassign_capability('tool/lp:templateread', $authrole->id);
|
||||
|
||||
|
@ -111,9 +111,9 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
|
||||
assign_capability('tool/lp:competencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:competencyread', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
assign_capability('tool/lp:planmanageall', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:planmanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:planmanageown', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:planviewall', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:planview', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:templatemanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
|
||||
assign_capability('tool/lp:templateread', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
|
||||
|
@ -1052,7 +1052,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
$this->assertEquals('nopermissions', $e->errorcode);
|
||||
}
|
||||
|
||||
assign_capability('tool/lp:plancreatedraft', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
assign_capability('tool/lp:plancreateown', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->setUser($this->user);
|
||||
|
@ -1095,7 +1095,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
}
|
||||
|
||||
unassign_capability('tool/lp:planmanageown', $this->userrole, $syscontext->id);
|
||||
unassign_capability('tool/lp:plancreatedraft', $this->userrole, $syscontext->id);
|
||||
unassign_capability('tool/lp:plancreateown', $this->userrole, $syscontext->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
try {
|
||||
|
@ -1133,7 +1133,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
$plan2['usercanupdate'] = false;
|
||||
$plan3['usercanupdate'] = false;
|
||||
|
||||
// You need planmanage, planmanageown or plancreatedraft to see draft plans.
|
||||
// You need planmanage, planmanageown or plancreateown to see draft plans.
|
||||
try {
|
||||
external::read_plan($plan1['id']);
|
||||
$this->fail('Exception expected due to not permissions to read draft plan');
|
||||
|
@ -1143,13 +1143,13 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
$this->assertEquals((Array)$plan2, external::read_plan($plan2['id']));
|
||||
$this->assertEquals((Array)$plan3, external::read_plan($plan3['id']));
|
||||
|
||||
assign_capability('tool/lp:plancreatedraft', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
assign_capability('tool/lp:plancreateown', CAP_ALLOW, $this->userrole, $syscontext->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
$this->assertEquals((Array)$plan1, external::read_plan($plan1['id']));
|
||||
|
||||
assign_capability('tool/lp:planviewown', CAP_PROHIBIT, $this->userrole, $syscontext->id);
|
||||
unassign_capability('tool/lp:plancreatedraft', $this->userrole, $syscontext->id);
|
||||
unassign_capability('tool/lp:plancreateown', $this->userrole, $syscontext->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
try {
|
||||
|
@ -1171,7 +1171,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
|
|||
|
||||
$this->assertTrue(external::delete_plan($plan1['id']));
|
||||
|
||||
unassign_capability('tool/lp:planmanageall', $this->creatorrole, $syscontext->id);
|
||||
unassign_capability('tool/lp:planmanage', $this->creatorrole, $syscontext->id);
|
||||
accesslib_clear_all_caches_for_unit_testing();
|
||||
|
||||
try {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$plugin->version = 2015052416; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015052418; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue