Ejemplo n.º 1
0
 public function test_can_manage_user()
 {
     $this->resetAfterTest(true);
     $manage = create_role('Manage', 'manage', 'Plan manager');
     $manageown = create_role('Manageown', 'manageown', 'Own plan manager');
     $u1 = $this->getDataGenerator()->create_user();
     $u2 = $this->getDataGenerator()->create_user();
     $u3 = $this->getDataGenerator()->create_user();
     $syscontext = context_system::instance();
     $u1context = context_user::instance($u1->id);
     $u2context = context_user::instance($u2->id);
     $u3context = context_user::instance($u3->id);
     assign_capability('moodle/competency:planmanage', CAP_ALLOW, $manage, $syscontext->id);
     assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $manageown, $u2context->id);
     role_assign($manage, $u1->id, $syscontext->id);
     role_assign($manageown, $u2->id, $syscontext->id);
     role_assign($manage, $u3->id, $u2context->id);
     accesslib_clear_all_caches_for_unit_testing();
     $this->setUser($u1);
     $this->assertTrue(plan::can_manage_user($u1->id));
     $this->assertTrue(plan::can_manage_user($u2->id));
     $this->assertTrue(plan::can_manage_user($u3->id));
     $this->setUser($u2);
     $this->assertFalse(plan::can_manage_user($u1->id));
     $this->assertTrue(plan::can_manage_user($u2->id));
     $this->assertFalse(plan::can_manage_user($u3->id));
     $this->setUser($u3);
     $this->assertFalse(plan::can_manage_user($u1->id));
     $this->assertTrue(plan::can_manage_user($u2->id));
     $this->assertFalse(plan::can_manage_user($u3->id));
 }
Ejemplo n.º 2
0
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     $data = new stdClass();
     $data->userid = $this->userid;
     $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
     $data->canreaduserevidence = user_evidence::can_read_user($this->userid);
     $data->canmanageuserplans = plan::can_manage_user($this->userid);
     // Attach standard objects as mustache can not parse \core_competency\plan objects.
     $data->plans = array();
     if ($this->plans) {
         foreach ($this->plans as $plan) {
             $exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
             $record = $exporter->export($output);
             $data->plans[] = $record;
         }
     }
     $data->navigation = array();
     foreach ($this->navigation as $button) {
         $data->navigation[] = $output->render($button);
     }
     return $data;
 }
Ejemplo n.º 3
0
    list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_plan($userid, $url, null, $pagetitle, $returntype);
} else {
    $plan = \core_competency\api::read_plan($id);
    // The userid parameter must be the same as the owner of the plan.
    if ($userid != $plan->get_userid()) {
        throw new coding_exception('Inconsistency between the userid parameter and the userid of the plan');
    }
    $pagetitle = get_string('editplan', 'tool_lp');
    list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_plan($userid, $url, $plan, $pagetitle, $returntype);
}
$output = $PAGE->get_renderer('tool_lp');
// Custom data to pass to the form.
$customdata = array('userid' => $userid, 'context' => $PAGE->context, 'persistent' => $plan);
// User can create plan if he can_manage_user with active/complete status
// or if he can_manage_user_draft with draft status.
$cancreate = \core_competency\plan::can_manage_user_draft($userid) || \core_competency\plan::can_manage_user($userid);
// If editing plan, check if user has permissions to edit it.
if ($plan != null) {
    if (!$plan->can_manage()) {
        throw new required_capability_exception($PAGE->context, 'moodle/competency:planmanage', 'nopermissions', '');
    }
    if (!$plan->can_be_edited()) {
        throw new coding_exception('Completed plan can not be edited');
    }
} else {
    if (!$cancreate) {
        throw new required_capability_exception($PAGE->context, 'moodle/competency:planmanage', 'nopermissions', '');
    }
}
$form = new \tool_lp\form\plan($url->out(false), $customdata);
if ($form->is_cancelled()) {