Various fixes and additions to resourceSet API.
This commit is contained in:
parent
1372050a7b
commit
5f5733e8b9
@ -1,9 +1,29 @@
|
||||
export function create ({ name }) {
|
||||
return this.createResourceSet(name)
|
||||
export function create ({ name, subjects, objects }) {
|
||||
return this.createResourceSet(name, subjects, objects)
|
||||
}
|
||||
|
||||
create.permission = 'admin'
|
||||
|
||||
create.params = {
|
||||
name: {
|
||||
type: 'string'
|
||||
},
|
||||
subjects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
objects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function delete_ ({ id }) {
|
||||
@ -13,44 +33,130 @@ export { delete_ as delete }
|
||||
|
||||
delete_.permission = 'admin'
|
||||
|
||||
delete_.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function set ({ id, name, subjects, objects }) {
|
||||
return this.updateResourceSet(id, { name, subjects, objects })
|
||||
}
|
||||
|
||||
set.permission = 'admin'
|
||||
|
||||
set.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
subjects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
},
|
||||
objects: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
},
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function get ({ id }) {
|
||||
return id == null
|
||||
? this.getAllResourceSets()
|
||||
: this.getResourceSet(id)
|
||||
return this.getResourceSet(id)
|
||||
}
|
||||
|
||||
get.permission = 'admin'
|
||||
|
||||
get.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addObject ({ object }) {
|
||||
return this.addObjectToResourceSet(object)
|
||||
export function getAll () {
|
||||
return this.getAllResourceSets()
|
||||
}
|
||||
|
||||
getAll.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addObject ({ id, object }) {
|
||||
return this.addObjectToResourceSet(object, id)
|
||||
}
|
||||
|
||||
addObject.permission = 'admin'
|
||||
|
||||
addObject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function removeObject ({ object }) {
|
||||
return this.removeObjectFromResourceSet(object)
|
||||
export function removeObject ({ id, object }) {
|
||||
return this.removeObjectFromResourceSet(object, id)
|
||||
}
|
||||
|
||||
removeObject.permission = 'admin'
|
||||
|
||||
removeObject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function addSubject ({ subject }) {
|
||||
export function addSubject ({ id, subject }) {
|
||||
return this.addSubjectToResourceSet(subject)
|
||||
}
|
||||
|
||||
addSubject.permission = 'admin'
|
||||
|
||||
addSubject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function removeSubject ({ subject }) {
|
||||
export function removeSubject ({ id, subject }) {
|
||||
return this.removeSubjectFromResourceSet(subject)
|
||||
}
|
||||
|
||||
removeSubject.permission = 'admin'
|
||||
|
||||
removeSubject.params = {
|
||||
id: {
|
||||
type: 'string'
|
||||
},
|
||||
object: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ export default class {
|
||||
this._sets = createRawObject()
|
||||
}
|
||||
|
||||
async createResourceSet (name) {
|
||||
async createResourceSet (name, subjects = [], objects = []) {
|
||||
const id = String(this._nextId++)
|
||||
const set = {
|
||||
id,
|
||||
name,
|
||||
objects: [],
|
||||
subjects: []
|
||||
objects,
|
||||
subjects
|
||||
}
|
||||
|
||||
return (this._sets[id] = set)
|
||||
@ -43,6 +43,19 @@ export default class {
|
||||
delete this._sets[id]
|
||||
}
|
||||
|
||||
async updateResourceSet (id, { name, subjects, objects }) {
|
||||
const set = await this.getResourceSet(id)
|
||||
if (name) {
|
||||
set.name = name
|
||||
}
|
||||
if (subjects) {
|
||||
set.subjects = subjects
|
||||
}
|
||||
if (objects) {
|
||||
set.objects = objects
|
||||
}
|
||||
}
|
||||
|
||||
async getAllResourceSets () {
|
||||
return this._sets
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user