简体   繁体   中英

Local Plugin permission issue not apply on course manager specifically - Moodle

I am new in Moodle and i have a task to create local plugin with course manager role. In my system i have bulk of users in specific course and they are categories in different roles. Some of are bind with students and rest of are Managers. For my case i have received request from the client to make a local plugin which generate multiple reports against student records. I have successfully made the plugin but the condition is this plugin only can access those one who has enrolled in course as a Manager. I m trying with following code which i share you in below but no success. right now only admin can access local plugin rest of are received error messages from the moodle state.

["Sorry, but you do not currently have permissions to do that Project view "]

No idea how it will be resolved.

Please advise.

local/project/db/access.php

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

$capabilities = array(

    'local/project:view' => array(
        'riskbitmask' => RISK_PERSONAL,
        'captype' => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
            'manager' => CAP_ALLOW
        ),
    'local/project:manage' => array(
        'captype' => 'write',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
            'manager' => CAP_ALLOW
        )
    )
    )
);

local/project/header.php

require(dirname(__FILE__).'/../../config.php');
global $DB;
//Get the system context
$url = new moodle_url('/local/project/index.php');

require_login();
require_capability('local/project:view', context_system::instance());

I have successfully achieved the target against moodle permission. I have used has_capability method with course context and check authenticity with require_capability . Following procedure only work with admin and manager other would not access until when they get full rights from the site administration.

local/project/db/access.php

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

$capabilities = array(

    'local/project:view' => array(
        'riskbitmask' => RISK_SPAM,
        'captype' => 'write',
        'contextlevel' => CONTEXT_COURSE,
        'archetypes' => array(
            'manager' => CAP_ALLOW,
        ),
    )
);

local/project/header.php

require(dirname(__FILE__).'/../../config.php');
require_login();

//Get the system context
$context = context_course::instance($course_id);

if (!has_capability('local/project:view', $context)) {
    require_capability('local/project:view', $context);
}

There is no standard Moodle role called 'Course manager'.

There is a role called 'Manager' ('manager') and another called 'Course creator' ('coursecreator').

If you have debugging enabled you might get some extra warning messages if there is anything wrong with the code (eg if you have not run the install/upgrade process to create the capabilities or if you have not increased the plugin version number after creating the capabilities).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM