Skip to content

Commit

Permalink
Added the RFC privileges but not integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 21, 2017
1 parent b766363 commit 61b7865
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/user/privilege/notused/IPrivilege.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IPrivilege {
description: string;
isAbstract: boolean;
name: string;
can(operation: string): boolean;
}
2 changes: 2 additions & 0 deletions lib/user/privilege/notused/IPrivilege.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
21 changes: 21 additions & 0 deletions lib/user/privilege/notused/Privilege.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
35 changes: 35 additions & 0 deletions lib/user/privilege/notused/Privilege.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions src/user/privilege/notused/IPrivilege.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

export interface IPrivilege
{
description : string;
isAbstract : boolean;
name : string;

can(operation : string) : boolean;
}
71 changes: 71 additions & 0 deletions src/user/privilege/notused/Privilege.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 61b7865

Please sign in to comment.