Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature hide button to students #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Plugin capabilities
*
* @package atto_question
* @copyright Richard Jones {@link http://richardnz.net/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$capabilities = array(

'atto/teamsmeeting:visible' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'coursecreator' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'student' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)
);
14 changes: 12 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@
* @param stdClass $fpoptions - unused.
*/
function atto_teamsmeeting_params_for_js($elementid, $options, $fpoptions) {
global $CFG, $SESSION, $USER;
global $CFG, $SESSION, $USER, $COURSE;

$coursecontext=context_course::instance($COURSE->id);
$disabled=false;

// If user don't have permission don't show button
if(!has_capability('atto/teamsmeeting:visible', $coursecontext)) {
$disabled=true;
}

$params = [
'clientdomain' => encode_url($CFG->wwwroot),
'appurl' => get_config('atto_teamsmeeting', 'meetingapplink'),
'locale' => (empty($SESSION->lang) ? $USER->lang : $SESSION->lang),
'msession' => sesskey()
'msession' => sesskey(),
'disabled' => $disabled
];
return $params;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ var COMPONENTNAME = 'atto_teamsmeeting',
URLINPUT: '.atto_teamsmeeting_urlentry'
},
TEMPLATE = '' +
'<form class="atto_form">' +
'<div class="meeting-app">' +
'<label class="meeting-app-label" for="meetingapp">' +
'{{get_string "createteamsmeeting" component}}' +
'</label>' +
'<iframe id="meetingapp" src="{{appurl}}?url={{clientdomain}}&locale={{locale}}&msession={{msession}}"></iframe>' +
'</div>' +
'<div class="mb-1">' +
'<label for="{{elementid}}_atto_teamsmeeting_urlentry">{{get_string "meetingurl" component}}</label>' +
'<input class="form-control fullwidth url {{CSS.URLINPUT}}" type="url" ' +
'id="{{elementid}}_atto_teamsmeeting_urlentry" size="32" disabled="disabled"/>' +
'</div>' +
'<div class="form-check">' +
'<input type="checkbox" class="form-check-input newwindow" id="{{elementid}}_{{CSS.NEWWINDOW}}"/>' +
'<label class="form-check-label" for="{{elementid}}_{{CSS.NEWWINDOW}}">' +
'{{get_string "openinnewwindow" component}}' +
'</label>' +
'</div>' +
'<div class="mdl-align">' +
'<br/>' +
'<button type="submit" class="btn btn-secondary submit">{{get_string "addlink" component}}</button>' +
'</div>' +
'</form>';
'<form class="atto_form">' +
'<div class="meeting-app">' +
'<label class="meeting-app-label" for="meetingapp">' +
'{{get_string "createteamsmeeting" component}}' +
'</label>' +
'<iframe id="meetingapp" src="{{appurl}}?url={{clientdomain}}&locale={{locale}}&msession={{msession}}"></iframe>' +
'</div>' +
'<div class="mb-1">' +
'<label for="{{elementid}}_atto_teamsmeeting_urlentry">{{get_string "meetingurl" component}}</label>' +
'<input class="form-control fullwidth url {{CSS.URLINPUT}}" type="url" ' +
'id="{{elementid}}_atto_teamsmeeting_urlentry" size="32" disabled="disabled"/>' +
'</div>' +
'<div class="form-check">' +
'<input type="checkbox" class="form-check-input newwindow" id="{{elementid}}_{{CSS.NEWWINDOW}}"/>' +
'<label class="form-check-label" for="{{elementid}}_{{CSS.NEWWINDOW}}">' +
'{{get_string "openinnewwindow" component}}' +
'</label>' +
'</div>' +
'<div class="mdl-align">' +
'<br/>' +
'<button type="submit" class="btn btn-secondary submit">{{get_string "addlink" component}}</button>' +
'</div>' +
'</form>';
Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {

/**
Expand Down Expand Up @@ -122,19 +122,25 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
*/
_msession: null,

initializer: function() {
initializer: function () {
this._clientdomain = this.get('clientdomain');
this._appurl = this.get('appurl');
this._locale = this.get('locale');
this._msession = this.get('msession');
// Add the teamsmeeting button first.
this.addButton({
icon: 'icon',
iconComponent: 'atto_teamsmeeting',
callback: this._displayDialogue,
tags: 'a',
tagMatchRequiresAll: false
});
// If we don't have the capability to view then give up.
this._disabled = this.get('disabled');
if (this._disabled) {
return;
} else {
// Add the teamsmeeting button first.
this.addButton({
icon: 'icon',
iconComponent: 'atto_teamsmeeting',
callback: this._displayDialogue,
tags: 'a',
tagMatchRequiresAll: false
});
}
},

/**
Expand All @@ -143,7 +149,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @method _displayDialogue
* @private
*/
_displayDialogue: function() {
_displayDialogue: function () {
// Store the current selection.
this._currentSelection = this.get('host').getSelection();
if (this._currentSelection === false) {
Expand Down Expand Up @@ -172,7 +178,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @method _resolveAnchors
* @private
*/
_resolveAnchors: function() {
_resolveAnchors: function () {
// Find the first anchor tag in the selection.
var selectednode = this.get('host').getSelectionParentNode(),
anchornodes,
Expand Down Expand Up @@ -222,8 +228,8 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @param {EventFacade} e
* @private
*/
_meetingcheck: function() {
if(document.getElementById('meetingapp').contentDocument) {
_meetingcheck: function () {
if (document.getElementById('meetingapp').contentDocument) {
var url = document.getElementById('meetingapp').contentDocument.location;
if (url !== '' && url.pathname.indexOf("teamsmeeting") > -1) {
var link = this._getqueryvariable('link', url);
Expand All @@ -241,11 +247,11 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @param {EventFacade} e
* @private
*/
_updateIframe: function(id, data) {
_updateIframe: function (id, data) {
if (data.status === 200) {
var dataobject = JSON.parse(data.responseText);
if (dataobject[2] !== null) {
var url = dataobject[0]+'?title=' + dataobject[1] + '&link=' + encodeURIComponent(dataobject[2]) +
var url = dataobject[0] + '?title=' + dataobject[1] + '&link=' + encodeURIComponent(dataobject[2]) +
'&options=' + encodeURIComponent(dataobject[3]);
this._content.one('#meetingapp').set('src', url);
}
Expand All @@ -260,7 +266,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @param {object} url
* @private
*/
_getqueryvariable: function(variable, url) {
_getqueryvariable: function (variable, url) {
var query = url.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
Expand All @@ -278,7 +284,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @param {EventFacade} e
* @private
*/
_setteamsmeeting: function(e) {
_setteamsmeeting: function (e) {
var input,
value;

Expand Down Expand Up @@ -314,7 +320,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @param {String} url URL the teamsmeeting will point to.
* @return {Node} The added Node.
*/
_setteamsmeetingOnSelection: function(url) {
_setteamsmeetingOnSelection: function (url) {
var host = this.get('host'),
teamsmeeting,
selectednode,
Expand Down Expand Up @@ -347,7 +353,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a

anchornodes = this._findSelectedAnchors(Y.one(selectednode));
// Add new window attributes if requested.
Y.Array.each(anchornodes, function(anchornode) {
Y.Array.each(anchornodes, function (anchornode) {
target = this._content.one('.newwindow');
if (target.get('checked')) {
anchornode.setAttribute('target', '_blank');
Expand All @@ -367,7 +373,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @return {Node|Boolean} The Node, or false if not found.
* @private
*/
_findSelectedAnchors: function(node) {
_findSelectedAnchors: function (node) {
var tagname = node.get('tagName'),
hit, hits;

Expand All @@ -378,7 +384,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a

// Search down but check that each node is part of the selection.
hits = [];
node.all('a').each(function(n) {
node.all('a').each(function (n) {
if (!hit && this.get('host').selectionContainsNode(n)) {
hits.push(n);
}
Expand All @@ -401,7 +407,7 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
* @return {Node} Node containing the dialogue content
* @private
*/
_getDialogueContent: function() {
_getDialogueContent: function () {
var template = Y.Handlebars.compile(TEMPLATE);

this._content = Y.Node.create(template({
Expand Down Expand Up @@ -456,7 +462,11 @@ Y.namespace('M.atto_teamsmeeting').Button = Y.Base.create('button', Y.M.editor_a
*/
msession: {
value: null
},
disabled: {
value: null
}

}
});

Expand Down
Loading