diff --git a/lib/user/privilege/notused/IPrivilege.d.ts b/lib/user/privilege/notused/IPrivilege.d.ts new file mode 100644 index 00000000..0334c3fd --- /dev/null +++ b/lib/user/privilege/notused/IPrivilege.d.ts @@ -0,0 +1,6 @@ +export interface IPrivilege { + description: string; + isAbstract: boolean; + name: string; + can(operation: string): boolean; +} diff --git a/lib/user/privilege/notused/IPrivilege.js b/lib/user/privilege/notused/IPrivilege.js new file mode 100644 index 00000000..ce03781e --- /dev/null +++ b/lib/user/privilege/notused/IPrivilege.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/user/privilege/notused/Privilege.d.ts b/lib/user/privilege/notused/Privilege.d.ts new file mode 100644 index 00000000..0aa3863e --- /dev/null +++ b/lib/user/privilege/notused/Privilege.d.ts @@ -0,0 +1,21 @@ +import { IPrivilege } from './IPrivilege'; +export declare class Privilege implements IPrivilege { + static all: Privilege; + static readACL: Privilege; + static readCurrentUserPrivilegeSet: Privilege; + static read: Privilege; + static writeACL: Privilege; + static writeProperties: Privilege; + static writeContent: Privilege; + static write: Privilege; + static unlock: Privilege; + subPrivileges: string[]; + description: string; + isAbstract: boolean; + isAll: boolean; + name: string; + constructor(name: string | Privilege, description: string, isAbstract: boolean, subPrivileges?: (string | Privilege)[]); + constructor(name: string | Privilege, description: string, isAbstract: boolean, isAll?: boolean); + can(operation: string): boolean; + toString(): string; +} diff --git a/lib/user/privilege/notused/Privilege.js b/lib/user/privilege/notused/Privilege.js new file mode 100644 index 00000000..b374d957 --- /dev/null +++ b/lib/user/privilege/notused/Privilege.js @@ -0,0 +1,35 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Privilege = (function () { + function Privilege(name, description, isAbstract, subPrivileges) { + this.description = description; + this.isAbstract = isAbstract; + this.isAll = subPrivileges && subPrivileges.constructor === Boolean ? subPrivileges : false; + if (!subPrivileges || subPrivileges.constructor !== Array) + subPrivileges = []; + var subPrivilegesCast = subPrivileges; + if (name.constructor === Privilege) + this.name = name.name; + else + this.name = name; + subPrivilegesCast.push(this.name); + this.subPrivileges = subPrivilegesCast.map(function (p) { return p.constructor === Privilege ? p.name : p; }); + } + Privilege.prototype.can = function (operation) { + return this.isAll || this.subPrivileges.some(function (p) { return p === operation; }); + }; + Privilege.prototype.toString = function () { + return this.name; + }; + return Privilege; +}()); +Privilege.all = new Privilege('DAV:all', 'Any operation', true, true); +Privilege.readACL = new Privilege('DAV:read-acl', 'Read ACL', true); +Privilege.readCurrentUserPrivilegeSet = new Privilege('DAV:read-current-user-privilege-set', 'Read current user privilege set property', true); +Privilege.read = new Privilege('DAV:read', 'Read any object', false, [Privilege.readACL, Privilege.readCurrentUserPrivilegeSet]); +Privilege.writeACL = new Privilege('DAV:write-acl', 'Write ACL', true); +Privilege.writeProperties = new Privilege('DAV:write-properties', 'Write properties', false); +Privilege.writeContent = new Privilege('DAV:write-content', 'Write resource content', false); +Privilege.write = new Privilege('DAV:write', 'Write any object', false, [Privilege.writeACL, Privilege.writeProperties, Privilege.writeContent]); +Privilege.unlock = new Privilege('DAV:unlock', 'Unlock resource', false); +exports.Privilege = Privilege; diff --git a/src/user/privilege/notused/IPrivilege.ts b/src/user/privilege/notused/IPrivilege.ts new file mode 100644 index 00000000..ec4ca8e9 --- /dev/null +++ b/src/user/privilege/notused/IPrivilege.ts @@ -0,0 +1,9 @@ + +export interface IPrivilege +{ + description : string; + isAbstract : boolean; + name : string; + + can(operation : string) : boolean; +} diff --git a/src/user/privilege/notused/Privilege.ts b/src/user/privilege/notused/Privilege.ts new file mode 100644 index 00000000..5942a1ce --- /dev/null +++ b/src/user/privilege/notused/Privilege.ts @@ -0,0 +1,71 @@ +import { IPrivilege } from './IPrivilege' + +/* +[DAV:, all] (aggregate, abstract) + | + +-- [DAV:, read] (aggregate) + | + +-- [DAV:, read-acl] (abstract) + +-- [DAV:, read-current-user-privilege-set] (abstract) + | + +-- [DAV:, write] (aggregate) + | + +-- [DAV:, write-acl] (abstract) + +-- [DAV:, write-properties] + +-- [DAV:, write-content] + | + +-- [DAV:, unlock] +*/ + +export class Privilege implements IPrivilege +{ + static all = new Privilege('DAV:all', 'Any operation', true, true) + + static readACL = new Privilege('DAV:read-acl', 'Read ACL', true) + static readCurrentUserPrivilegeSet = new Privilege('DAV:read-current-user-privilege-set', 'Read current user privilege set property', true) + static read = new Privilege('DAV:read', 'Read any object', false, [ Privilege.readACL, Privilege.readCurrentUserPrivilegeSet ]) + + static writeACL = new Privilege('DAV:write-acl', 'Write ACL', true) + static writeProperties = new Privilege('DAV:write-properties', 'Write properties', false) + static writeContent = new Privilege('DAV:write-content', 'Write resource content', false) + static write = new Privilege('DAV:write', 'Write any object', false, [ Privilege.writeACL, Privilege.writeProperties, Privilege.writeContent ]) + + static unlock = new Privilege('DAV:unlock', 'Unlock resource', false) + + subPrivileges : string[] // Privileges included by this privilege (always include self) + description : string // Text to display to human users + isAbstract : boolean // RFC3744 : true = cannot be used as a standalone privilege + isAll : boolean // true = includes all privileges + name : string // unique name of the privilege (might be used in resources as id) + + constructor(name : string | Privilege, description : string, isAbstract : boolean, subPrivileges ?: (string | Privilege)[]) + constructor(name : string | Privilege, description : string, isAbstract : boolean, isAll ?: boolean) + constructor(name : string | Privilege, description : string, isAbstract : boolean, subPrivileges ?: (string | Privilege)[] | boolean) + { + this.description = description; + this.isAbstract = isAbstract; + this.isAll = subPrivileges && subPrivileges.constructor === Boolean ? subPrivileges as boolean : false; + + if(!subPrivileges || subPrivileges.constructor !== Array) + subPrivileges = []; + const subPrivilegesCast = subPrivileges as (string | Privilege)[]; + + if(name.constructor === Privilege) + this.name = (name as Privilege).name; + else + this.name = name as string; + + subPrivilegesCast.push(this.name); + this.subPrivileges = subPrivilegesCast.map((p) => p.constructor === Privilege ? (p as Privilege).name : p as string); + } + + can(operation : string) : boolean + { + return this.isAll || this.subPrivileges.some((p) => p === operation); + } + + toString() + { + return this.name; + } +}