From 70d3807666a86ea6313cfcaf1eae04c014abcb91 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 23 Sep 2015 17:49:18 +0200 Subject: [PATCH] Add Permission.js --- .../files/js/WoltLab/WCF/Permission.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 wcfsetup/install/files/js/WoltLab/WCF/Permission.js diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Permission.js b/wcfsetup/install/files/js/WoltLab/WCF/Permission.js new file mode 100644 index 0000000000..7ac22271f3 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLab/WCF/Permission.js @@ -0,0 +1,63 @@ +/** + * Manages user permissions. + * + * @author Matthias Schmidt + * @copyright 2001-2015 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLab/WCF/Permission + */ +define(['Dictionary'], function(Dictionary) { + "use strict"; + + var _permissions = new Dictionary(); + + /** + * @exports WoltLab/WCF/Permission + */ + var Permission = { + /** + * Adds a single permission to the store. + * + * @param {string} permission permission name + * @param {boolean} value permission value + */ + add: function(permission, value) { + if (typeof value !== "boolean") { + throw new TypeError("Permission value has to be boolean."); + } + + _permissions.set(permission, value); + }, + + /** + * Adds all the permissions in the given object to the store. + * + * @param {Object.} object permission list + */ + addObject: function(object) { + for (var key in object) { + if (object.hasOwnProperty(key)) { + this.addPermission(key, object[key]); + } + } + }, + + /** + * Returns the value of a permission. + * + * If the permission is unknown, false is returned. + * + * @param {string} permission permission name + * @return {boolean} permission value + */ + get: function(permission) { + if (_permissions.has(permission)) { + return _permissions.get(permission); + } + + return false; + } + }; + + return Permission; +}); -- 2.20.1