Commit ab227834 authored by Jörg Richter's avatar Jörg Richter

REST client: make getPermissions() generic

BREAKING CHANGE

Both REST client methods

    getTopicPermissions(id)
    getAssocPermissions(id)

are unified into one:

    getPermissions(id)

See dmx-platform/dmx-platform#341
parent 77fb73ff
Pipeline #10240 passed with stage
in 1 second
This diff is collapsed.
......@@ -6,7 +6,7 @@ import typeCache from './type-cache'
import permCache from './permission-cache'
import utils from './utils'
console.log('[DMX] Client Library 2020/05/01')
console.log('[DMX] Client Library 2020/06/20')
export default {
......
......@@ -66,6 +66,13 @@ class DMXObject {
return restClient.getRelatedTopicsWithoutChilds(this.id)
}
/**
* @return a promise for a true/false value
*/
isWritable () {
return permCache.isWritable(this.id)
}
/**
* Operates in-place
*
......@@ -198,13 +205,6 @@ class Topic extends DMXObject {
return restClient.updateTopic(this)
}
/**
* @return a promise for a true/false value
*/
isWritable () {
return permCache.isTopicWritable(this.id)
}
isTopic () {
return true
}
......@@ -313,13 +313,6 @@ class Assoc extends DMXObject {
return restClient.updateAssoc(this)
}
/**
* @return a promise for a true/false value
*/
isWritable () {
return permCache.isAssocWritable(this.id)
}
isTopic () {
return false
}
......
import restClient from './rest-client'
export default {
isTopicWritable,
isAssocWritable,
isWritable,
clear
}
// Key is a topic/association ID.
// Key is a topic/assoc ID.
// Value is a promise for a permissions object:
// {
// "dmx.accesscontrol.operation.write": true|false
......@@ -20,24 +19,12 @@ export default {
let permissionCache = {}
/**
* @param id a topic/assoc ID.
*
* @return a promise for a true/false value
*/
function isTopicWritable (id) {
return _isWritable(id, restClient.getTopicPermissions)
}
/**
* @return a promise for a true/false value
*/
function isAssocWritable (id) {
return _isWritable(id, restClient.getAssocPermissions)
}
/**
* @return a promise for a true/false value
*/
function _isWritable (id, retrievalFunc) {
return (permissionCache[id] || (permissionCache[id] = retrievalFunc(id))).then(permissions =>
function isWritable (id) {
return (permissionCache[id] || (permissionCache[id] = restClient.getPermissions(id))).then(permissions =>
permissions['dmx.accesscontrol.operation.write']
)
}
......
......@@ -407,14 +407,8 @@ export default {
)
},
getTopicPermissions (id) {
return http.get(`/accesscontrol/topic/${id}`).then(response =>
response.data
)
},
getAssocPermissions (id) {
return http.get(`/accesscontrol/assoc/${id}`).then(response =>
getPermissions (id) {
return http.get(`/accesscontrol/object/${id}`).then(response =>
response.data
)
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment