-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the RFC privileges but not integrated
- Loading branch information
1 parent
b766363
commit 61b7865
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |