Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / Permission.js
1 /**
2 * Manages user permissions.
3 *
4 * @author Matthias Schmidt
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Permission
8 */
9 define(['Dictionary'], function(Dictionary) {
10 "use strict";
11
12 var _permissions = new Dictionary();
13
14 /**
15 * @exports WoltLabSuite/Core/Permission
16 */
17 return {
18 /**
19 * Adds a single permission to the store.
20 *
21 * @param {string} permission permission name
22 * @param {boolean} value permission value
23 */
24 add: function(permission, value) {
25 if (typeof value !== "boolean") {
26 throw new TypeError("Permission value has to be boolean.");
27 }
28
29 _permissions.set(permission, value);
30 },
31
32 /**
33 * Adds all the permissions in the given object to the store.
34 *
35 * @param {Object.<string, boolean>} object permission list
36 */
37 addObject: function(object) {
38 for (var key in object) {
39 if (objOwns(object, key)) {
40 this.add(key, object[key]);
41 }
42 }
43 },
44
45 /**
46 * Returns the value of a permission.
47 *
48 * If the permission is unknown, false is returned.
49 *
50 * @param {string} permission permission name
51 * @return {boolean} permission value
52 */
53 get: function(permission) {
54 if (_permissions.has(permission)) {
55 return _permissions.get(permission);
56 }
57
58 return false;
59 }
60 };
61 });