MDL-53551 tool_lp: Can't have a read-only view of competency frameworks
This commit is contained in:
committed by
Frederic Massart
parent
cd378576e7
commit
d57c079a6c
+1
-1
@@ -1 +1 @@
|
||||
define(["core/ajax","core/notification","core/templates","tool_lp/tree","tool_lp/competency_outcomes","jquery"],function(a,b,c,d,e,f){var g={},h=0,i="",j="",k="",l=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),l(d,b))},m=function(b){var e=f.Deferred();return c.render("tool_lp/loading",{}).done(function(m,n){c.replaceNodeContents(f(j),m,n);var o=a.call([{methodname:"tool_lp_search_competencies",args:{searchtext:b,competencyframeworkid:h}}]);o[0].done(function(a){g={};var b=0;for(b=0;b<a.length;b++)g[a[b].id]=a[b];var h=[],m=!1;for(b=0;b<a.length;b++)m=a[b],0===parseInt(m.parentid,10)&&(h.push(m),l(m,a));var n={shortname:i,competencies:h};c.render("tool_lp/competencies_tree_root",n).done(function(a,b){c.replaceNodeContents(f(j),f(a).html(),b);var h=new d(j,!1);if(k){var i=f(j).find("[data-id="+k+"]");i.length&&(h.selectItem(i),h.updateFocus(i))}e.resolve(g)}).fail(e.reject)}).fail(e.reject)}),e.promise()},n=function(a,b){var c=b.selected;k=c.attr("data-id")};return{init:function(a,c,d,e){h=a,i=c,j=e,m(d).fail(b.exception),this.on("selectionchanged",n)},on:function(a,b){f(j).on(a,b)},getChildren:function(a){var b=[];return f.each(g,function(c,d){d.parentid==a&&b.push(d)}),b},getCompetencyFrameworkId:function(){return h},getCompetency:function(a){return g[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},hasChildren:function(a){return this.getChildren(a).length>0},hasRule:function(a){var b=this.getCompetency(a);return b?b.ruleoutcome!=e.OUTCOME_NONE&&b.ruletype:!1},reloadCompetencies:function(){return m("").fail(b.exception)},listCompetencies:function(){return g}}});
|
||||
define(["core/ajax","core/notification","core/templates","tool_lp/tree","tool_lp/competency_outcomes","jquery"],function(a,b,c,d,e,f){var g={},h=0,i="",j="",k="",l=!1,m=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),m(d,b))},n=function(b){var e=f.Deferred();return c.render("tool_lp/loading",{}).done(function(n,o){c.replaceNodeContents(f(j),n,o);var p=a.call([{methodname:"tool_lp_search_competencies",args:{searchtext:b,competencyframeworkid:h}}]);p[0].done(function(a){g={};var b=0;for(b=0;b<a.length;b++)g[a[b].id]=a[b];var h=[],n=!1;for(b=0;b<a.length;b++)n=a[b],0===parseInt(n.parentid,10)&&(h.push(n),m(n,a));var o={shortname:i,canmanage:l,competencies:h};c.render("tool_lp/competencies_tree_root",o).done(function(a,b){c.replaceNodeContents(f(j),f(a).html(),b);var h=new d(j,!1);if(k){var i=f(j).find("[data-id="+k+"]");i.length&&(h.selectItem(i),h.updateFocus(i))}e.resolve(g)}).fail(e.reject)}).fail(e.reject)}),e.promise()},o=function(a,b){var c=b.selected;k=c.attr("data-id")};return{init:function(a,c,d,e,f){h=a,i=c,l=f,j=e,n(d).fail(b.exception),this.on("selectionchanged",o)},on:function(a,b){f(j).on(a,b)},getChildren:function(a){var b=[];return f.each(g,function(c,d){d.parentid==a&&b.push(d)}),b},getCompetencyFrameworkId:function(){return h},getCompetency:function(a){return g[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},hasChildren:function(a){return this.getChildren(a).length>0},hasRule:function(a){var b=this.getCompetency(a);return b?b.ruleoutcome!=e.OUTCOME_NONE&&b.ruletype:!1},reloadCompetencies:function(){return n("").fail(b.exception)},listCompetencies:function(){return g}}});
|
||||
@@ -1 +1 @@
|
||||
define(["jquery","core/notification","tool_lp/dialogue","core/str","core/ajax","core/templates"],function(a,b,c,d,e,f){var g=function(b){a(b).on("click",this.configureSettings.bind(this))};return g.prototype._dialogue=null,g.prototype.configureSettings=function(e){var g=a(e.target).closest("a").data("courseid"),h=a(e.target).closest("a").data("pushratingstouserplans"),i={courseid:g,pushratingstouserplans:h};e.preventDefault(),f.render("tool_lp/course_competency_settings",i).done(function(a){d.get_string("configurecoursecompetencysettings","tool_lp").done(function(b){this._dialogue=new c(b,a,this.addListeners.bind(this))}.bind(this)).fail(b.exception)}.bind(this)).fail(b.exception)},g.prototype.addListeners=function(){var a=this._find('[data-action="save"]');a.on("click",this.saveSettings.bind(this));var b=this._find('[data-action="cancel"]');b.on("click",this.cancelChanges.bind(this))},g.prototype.cancelChanges=function(a){a.preventDefault(),this._dialogue.close()},g.prototype._find=function(b){return a('[data-region="coursecompetencysettings"]').find(b)},g.prototype.saveSettings=function(a){a.preventDefault();var c=this._find('input[name="pushratingstouserplans"]:checked').val(),d=this._find('input[name="courseid"]').val();e.call([{methodname:"tool_lp_update_course_competency_settings",args:{courseid:d,pushratingstouserplans:c}}])[0].done(function(){this.refreshCourseCompetenciesPage()}.bind(this)).fail(b.exception)},g.prototype.refreshCourseCompetenciesPage=function(){var c=this._find('input[name="courseid"]').val();e.call([{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:c}}])[0].done(function(c){f.render("tool_lp/course_competencies_page",c).done(function(b,c){a('[data-region="coursecompetenciespage"]').replaceWith(b),f.runTemplateJS(c),this._dialogue.close()}.bind(this)).fail(b.exception)}.bind(this)).fail(b.exception)},g});
|
||||
define(["jquery","core/notification","tool_lp/dialogue","core/str","core/ajax","core/templates"],function(a,b,c,d,e,f){var g=function(b){a(b).on("click",this.configureSettings.bind(this))};return g.prototype._dialogue=null,g.prototype.configureSettings=function(e){var g=a(e.target).closest("a").data("courseid"),h=a(e.target).closest("a").data("pushratingstouserplans"),i={courseid:g,settings:{pushratingstouserplans:h}};e.preventDefault(),f.render("tool_lp/course_competency_settings",i).done(function(a){d.get_string("configurecoursecompetencysettings","tool_lp").done(function(b){this._dialogue=new c(b,a,this.addListeners.bind(this))}.bind(this)).fail(b.exception)}.bind(this)).fail(b.exception)},g.prototype.addListeners=function(){var a=this._find('[data-action="save"]');a.on("click",this.saveSettings.bind(this));var b=this._find('[data-action="cancel"]');b.on("click",this.cancelChanges.bind(this))},g.prototype.cancelChanges=function(a){a.preventDefault(),this._dialogue.close()},g.prototype._find=function(b){return a('[data-region="coursecompetencysettings"]').find(b)},g.prototype.saveSettings=function(a){a.preventDefault();var c=this._find('input[name="pushratingstouserplans"]:checked').val(),d=this._find('input[name="courseid"]').val(),f={pushratingstouserplans:c};e.call([{methodname:"tool_lp_update_course_competency_settings",args:{courseid:d,settings:f}}])[0].done(function(){this.refreshCourseCompetenciesPage()}.bind(this)).fail(b.exception)},g.prototype.refreshCourseCompetenciesPage=function(){var c=this._find('input[name="courseid"]').val();e.call([{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:c}}])[0].done(function(c){f.render("tool_lp/course_competencies_page",c).done(function(b,c){a('[data-region="coursecompetenciespage"]').replaceWith(b),f.runTemplateJS(c),this._dialogue.close()}.bind(this)).fail(b.exception)}.bind(this)).fail(b.exception)},g});
|
||||
@@ -40,6 +40,9 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'too
|
||||
/** @var {String} currentNodeId - The data-id of the current node in the tree. */
|
||||
var currentNodeId = '';
|
||||
|
||||
/** @var {Boolean} competencyFramworkCanManage - Can manage the competencies framework */
|
||||
var competencyFramworkCanManage = false;
|
||||
|
||||
/**
|
||||
* Build a tree from the flat list of competencies.
|
||||
* @param {Object} parent The parent competency.
|
||||
@@ -96,6 +99,7 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'too
|
||||
}
|
||||
var context = {
|
||||
shortname: competencyFrameworkShortName,
|
||||
canmanage: competencyFramworkCanManage,
|
||||
competencies: children
|
||||
};
|
||||
templates.render('tool_lp/competencies_tree_root', context).done(function(html, js) {
|
||||
@@ -127,7 +131,6 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'too
|
||||
currentNodeId = node.attr('data-id');
|
||||
};
|
||||
|
||||
|
||||
return /** @alias module:tool_lp/competencytree */ {
|
||||
// Public variables and functions.
|
||||
/**
|
||||
@@ -137,10 +140,12 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'too
|
||||
* @param {String} shortname The framework shortname
|
||||
* @param {String} search The current search string
|
||||
* @param {String} selector The selector for the tree div
|
||||
* @param {Boolean} canmanage Can manage the competencies
|
||||
*/
|
||||
init: function(id, shortname, search, selector) {
|
||||
init: function(id, shortname, search, selector, canmanage) {
|
||||
competencyFrameworkId = id;
|
||||
competencyFrameworkShortName = shortname;
|
||||
competencyFramworkCanManage = canmanage;
|
||||
treeSelector = selector;
|
||||
loadCompetencies(search).fail(notification.exception);
|
||||
|
||||
|
||||
@@ -471,4 +471,43 @@ class competency_framework extends persistent {
|
||||
// Return the uniq idnumber.
|
||||
return $currentidnumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the current user can manage the framework.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_manage() {
|
||||
return self::can_manage_context($this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the current user can manage the framework.
|
||||
*
|
||||
* @param context $context
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_manage_context($context) {
|
||||
return has_capability('tool/lp:competencymanage', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the current user can read the framework.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_read() {
|
||||
return self::can_read_context($this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the current user can read the framework.
|
||||
*
|
||||
* @param context $context
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_read_context($context) {
|
||||
return has_capability('tool/lp:competencyview', $context) || self::can_manage_context($context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ use moodle_url;
|
||||
use context;
|
||||
use context_system;
|
||||
use tool_lp\api;
|
||||
use tool_lp\competency_framework;
|
||||
use tool_lp\external\competency_framework_exporter;
|
||||
|
||||
/**
|
||||
@@ -66,12 +67,14 @@ class manage_competency_frameworks_page implements renderable, templatable {
|
||||
public function __construct(context $pagecontext) {
|
||||
$this->pagecontext = $pagecontext;
|
||||
|
||||
$addpage = new single_button(
|
||||
new moodle_url('/admin/tool/lp/editcompetencyframework.php', array('pagecontextid' => $this->pagecontext->id)),
|
||||
get_string('addnewcompetencyframework', 'tool_lp'),
|
||||
'get'
|
||||
);
|
||||
$this->navigation[] = $addpage;
|
||||
if (competency_framework::can_manage_context($this->pagecontext)) {
|
||||
$addpage = new single_button(
|
||||
new moodle_url('/admin/tool/lp/editcompetencyframework.php', array('pagecontextid' => $this->pagecontext->id)),
|
||||
get_string('addnewcompetencyframework', 'tool_lp'),
|
||||
'get'
|
||||
);
|
||||
$this->navigation[] = $addpage;
|
||||
}
|
||||
|
||||
$this->competencyframeworks = api::list_frameworks('shortname', 'ASC', 0, 0, $this->pagecontext);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ require_login();
|
||||
$pagecontext = context::instance_by_id($pagecontextid);
|
||||
$framework = \tool_lp\api::read_framework($id);
|
||||
$context = $framework->get_context();
|
||||
require_capability('tool/lp:competencymanage', $context);
|
||||
|
||||
if (!\tool_lp\competency_framework::can_read_context($context)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
|
||||
}
|
||||
|
||||
$title = get_string('competencies', 'tool_lp');
|
||||
$pagetitle = get_string('competenciesforframework', 'tool_lp', $framework->get_shortname());
|
||||
|
||||
@@ -33,7 +33,10 @@ $url->param('pagecontextid', $pagecontextid);
|
||||
|
||||
require_login();
|
||||
\tool_lp\api::require_enabled();
|
||||
require_capability('tool/lp:competencymanage', $context);
|
||||
|
||||
if (!\tool_lp\competency_framework::can_read_context($context)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:competencyview', 'nopermissions', '');
|
||||
}
|
||||
|
||||
$title = get_string('competencies', 'tool_lp');
|
||||
$pagetitle = get_string('competencyframeworks', 'tool_lp');
|
||||
|
||||
@@ -115,8 +115,8 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor
|
||||
|
||||
// We check permissions before renderring the links.
|
||||
$templatereadcapability = \tool_lp\template::can_read_context($coursecategorycontext);
|
||||
$competencymanagecapability = has_capability('tool/lp:competencymanage', $coursecategorycontext);
|
||||
if (!$templatereadcapability && !$competencymanagecapability) {
|
||||
$competencyreadcapability = \tool_lp\competency_framework::can_read_context($coursecategorycontext);
|
||||
if (!$templatereadcapability && !$competencyreadcapability) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor
|
||||
}
|
||||
|
||||
// The link to the competency frameworks page.
|
||||
if ($competencymanagecapability) {
|
||||
if ($competencyreadcapability) {
|
||||
$title = get_string('competencyframeworks', 'tool_lp');
|
||||
$path = new moodle_url("/admin/tool/lp/competencyframeworks.php", array('pagecontextid' => $coursecategorycontext->id));
|
||||
$settingsnode = navigation_node::create($title,
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<li data-id="{{id}}">
|
||||
{{#canmanage}}
|
||||
<span draggable="true">
|
||||
{{shortname}}
|
||||
</span>
|
||||
{{/canmanage}}
|
||||
{{^canmanage}}
|
||||
<span>
|
||||
{{shortname}}
|
||||
</span>
|
||||
{{/canmanage}}
|
||||
{{#haschildren}}
|
||||
<ul>
|
||||
{{#children}}
|
||||
|
||||
@@ -122,7 +122,8 @@ require(['tool_lp/tree', 'tool_lp/competencytree', 'tool_lp/competencyactions',
|
||||
treeModel.init({{framework.id}},
|
||||
'{{framework.shortname}}',
|
||||
'{{search}}',
|
||||
'[data-enhance=tree]');
|
||||
'[data-enhance=tree]',
|
||||
{{canmanage}});
|
||||
|
||||
actions.init(treeModel, {{pagecontextid}}, '{{{framework.taxonomies}}}', {{{rulesmodules}}});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user