@qikdev/sdk 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/access.html +16371 -0
- package/dist/api.html +1503 -0
- package/dist/auth.html +8455 -0
- package/dist/cache.html +1135 -0
- package/dist/content.html +10067 -0
- package/dist/files.html +3415 -0
- package/dist/filter.html +4973 -0
- package/dist/geo.html +3851 -0
- package/dist/global.html +328 -0
- package/dist/index.html +96 -0
- package/dist/main.js +1100 -1126
- package/dist/module-QikStorage-CookieStorageAdapter.html +1177 -0
- package/dist/module-QikStorage-LocalStorageAdapter.html +329 -0
- package/dist/module-QikStorage-StorageAdapter.html +3457 -0
- package/dist/module-QikStorage.html +1445 -0
- package/dist/qik.access.js.html +904 -0
- package/dist/qik.api.js.html +409 -0
- package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
- package/dist/qik.cache.js.html +125 -0
- package/dist/qik.content.js.html +967 -0
- package/dist/qik.core.js.html +322 -0
- package/dist/qik.files.js.html +249 -0
- package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +2 -2
- package/dist/qik.geo.js.html +963 -0
- package/dist/qik.socket.js.html +451 -0
- package/dist/qik.storage.js.html +375 -0
- package/dist/qik.system.js.html +117 -0
- package/dist/qik.utils.js.html +1542 -0
- package/dist/socket.html +2975 -0
- package/dist/{docs/styles → styles}/jsdoc.css +2 -2
- package/dist/system.html +523 -0
- package/package.json +2 -2
- package/src/api/qik.access.js +2 -53
- package/src/api/qik.socket.js +51 -10
- package/src/version.js +1 -1
- package/dist/docs/access.html +0 -3826
- package/dist/docs/api.html +0 -1356
- package/dist/docs/auth.html +0 -2180
- package/dist/docs/cache.html +0 -351
- package/dist/docs/content.html +0 -2560
- package/dist/docs/files.html +0 -779
- package/dist/docs/filter.html +0 -1355
- package/dist/docs/index.html +0 -96
- package/dist/docs/qik.access.js.html +0 -790
- package/dist/docs/qik.api.js.html +0 -511
- package/dist/docs/qik.cache.js.html +0 -131
- package/dist/docs/qik.content.js.html +0 -918
- package/dist/docs/qik.core.js.html +0 -301
- package/dist/docs/qik.files.js.html +0 -219
- package/dist/docs/qik.socket.js.html +0 -416
- package/dist/docs/qik.system.js.html +0 -117
- package/dist/docs/qik.utils.js.html +0 -1467
- package/dist/docs/socket.html +0 -810
- package/dist/docs/system.html +0 -197
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
- /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
- /package/dist/{docs/scripts → scripts}/nav.js +0 -0
- /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
- /package/dist/{docs/scripts → scripts}/search.js +0 -0
- /package/dist/{docs/styles → styles}/prettify.css +0 -0
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>qik.access.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
29
|
+
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li></ul></li><li></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.sync">sync</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li></li><li><a href="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li></ul></li><li></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li></ul></li><li></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li><li></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li><li></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">qik.access.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
46
|
+
* Creates a new Access Module instance.
|
|
47
|
+
* This module provides a number of helper functions for managing and understanding permissions of the current
|
|
48
|
+
* application or user
|
|
49
|
+
* @alias access
|
|
50
|
+
* @constructor
|
|
51
|
+
* @hideconstructor
|
|
52
|
+
* @param {QikCore} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
var QikAccess = function (QikCore) {
|
|
56
|
+
if (!QikCore.auth) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Can't Instantiate QikAccess before QikAccess has been initialized`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!QikCore.utils) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Can't Instantiate QikAccess before QikCore.utils has been initialized`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//////////////////////////////////
|
|
69
|
+
|
|
70
|
+
var service = {};
|
|
71
|
+
|
|
72
|
+
///////////////////////////////////////////////
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @alias access.hasFeature
|
|
76
|
+
* @description Checks if a user has a specific feature enabled for their organisation
|
|
77
|
+
* @param {Object} user The user to check
|
|
78
|
+
* @param {String} feature The feature to check is enabled/disabled
|
|
79
|
+
* @example
|
|
80
|
+
* const user = sdk.auth.getCurrentUser();
|
|
81
|
+
* const formsFeatureIsEnabled = sdk.access.hasFeature(user, 'forms');
|
|
82
|
+
*/
|
|
83
|
+
service.hasFeature = function (user, feature) {
|
|
84
|
+
const features = user?.organisation?.features || {};
|
|
85
|
+
if (features.all) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return Boolean(features[feature]);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
///////////////////////////////////////////////
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @alias access.isAdministrator
|
|
95
|
+
* @description Check if a user object is an administrator
|
|
96
|
+
* @param {Object} user The user session to check
|
|
97
|
+
* @example
|
|
98
|
+
* const userIsAnAdministrator = sdk.access.isAdministrator({firstName:'Jeffrey', lastName:'Winger', ...});
|
|
99
|
+
*/
|
|
100
|
+
service.isAdministrator = function (user) {
|
|
101
|
+
return user && user?.userType == "administrator";
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
///////////////////////////////////////////////
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @alias access.getAllDescendants
|
|
108
|
+
* @description Get all children of a specified scope
|
|
109
|
+
* @param {Object} scope A scope object with child scopes
|
|
110
|
+
* @example
|
|
111
|
+
* const childScopes = sdk.access.getAllDescendants({title:'Global', children:[{title:'Australia', ...}, {title:'New Zealand', ...}]});
|
|
112
|
+
*/
|
|
113
|
+
service.getAllDescendants = function (scope) {
|
|
114
|
+
//Start by including the scope id
|
|
115
|
+
var results = [];
|
|
116
|
+
|
|
117
|
+
addScope(scope);
|
|
118
|
+
|
|
119
|
+
function addScope(entry) {
|
|
120
|
+
//Add this scope to the results
|
|
121
|
+
var id = QikCore.utils.id(entry);
|
|
122
|
+
results.push(id);
|
|
123
|
+
|
|
124
|
+
(entry.children || []).forEach(function (child) {
|
|
125
|
+
addScope(child);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return results;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
///////////////////////////////////////////////
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @alias access.hashPermissions
|
|
135
|
+
* @description Get a lookup of all permissions a user has been granted
|
|
136
|
+
* @param {Object} user A user session object
|
|
137
|
+
* @example
|
|
138
|
+
* const permissions = sdk.access.hashPermissions({firstName:'Mighty', lastName:'Mouse', permissionSets:[...], ...});
|
|
139
|
+
*/
|
|
140
|
+
service.hashPermissions = function (user) {
|
|
141
|
+
var results = {};
|
|
142
|
+
|
|
143
|
+
for (var key in user?.permissions || {}) {
|
|
144
|
+
//Get the permission set
|
|
145
|
+
var permissionSet = user?.permissions[key];
|
|
146
|
+
|
|
147
|
+
//Get all Scope ids from the permission set
|
|
148
|
+
var allIDs = service.getAllDescendants(permissionSet);
|
|
149
|
+
|
|
150
|
+
//For each permission defined in the set
|
|
151
|
+
(permissionSet.permissions || []).forEach(function (permissionString) {
|
|
152
|
+
//Include the top scope
|
|
153
|
+
if (!results[permissionString]) {
|
|
154
|
+
results[permissionString] = [];
|
|
155
|
+
}
|
|
156
|
+
results[permissionString] = [
|
|
157
|
+
...new Set(results[permissionString].concat(allIDs)),
|
|
158
|
+
];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
///////////////////////////////////////////////
|
|
163
|
+
|
|
164
|
+
return results;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
///////////////////////////////////////////////
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @alias access.allUserScopes
|
|
171
|
+
* @description Return an array of ids of all scopes that a given user has been granted a permission in
|
|
172
|
+
* @param {Object} user A user session object
|
|
173
|
+
* @example
|
|
174
|
+
* const permissions = sdk.access.allUserScopes({firstName:'Mighty', lastName:'Mouse', permissionSets:[...], ...});
|
|
175
|
+
*
|
|
176
|
+
* // Would result in:
|
|
177
|
+
* ['61eca4746971e75c1fc670cf', '61eca4746971e75c1fc670ca', '77eca4746971e75c1fc670cf'],
|
|
178
|
+
*/
|
|
179
|
+
service.allUserScopes = function (user) {
|
|
180
|
+
var collected = {};
|
|
181
|
+
var permissions = user?.permissions || {};
|
|
182
|
+
|
|
183
|
+
////////////////////////
|
|
184
|
+
|
|
185
|
+
function pluckScope(scopeObject) {
|
|
186
|
+
if (!scopeObject) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var scopeID = QikCore.utils.id(scopeObject);
|
|
191
|
+
if (!scopeID) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//Add to the collection
|
|
196
|
+
collected[scopeID] = 1;
|
|
197
|
+
|
|
198
|
+
//If there are children, then recursively pluck the ids
|
|
199
|
+
if (scopeObject.children && scopeObject.children.length) {
|
|
200
|
+
scopeObject.children.forEach(function (scope) {
|
|
201
|
+
pluckScope(scope);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
////////////////////////
|
|
207
|
+
|
|
208
|
+
for (var scopeID in permissions) {
|
|
209
|
+
pluckScope(permissions[scopeID]);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
////////////////////////
|
|
213
|
+
|
|
214
|
+
return Object.keys(collected);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
///////////////////////////////////////////////
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @alias access.actionableScopes
|
|
221
|
+
* @description Return an array of all scopes that a given user can perform a specified action in
|
|
222
|
+
* @param {Object} user A user session object
|
|
223
|
+
* @param {String} action The action
|
|
224
|
+
* @param {String} definition The defined type of item the action will be performed on
|
|
225
|
+
* @param {String} type The basic type of item the action will be performed on
|
|
226
|
+
* @param {Object} options Additional options and parameters
|
|
227
|
+
* @example
|
|
228
|
+
* const user = sdk.auth.getCurrentUser();
|
|
229
|
+
* const canCreateInScopes = sdk.access.actionableScopes(user, 'create', 'car', 'article');
|
|
230
|
+
* const canDeleteInScopes = sdk.access.actionableScopes(user, 'delete', 'profile');
|
|
231
|
+
*
|
|
232
|
+
* // Would result in something like:
|
|
233
|
+
* ['61eca4746971e75c1fc670cf', '61eca4746971e75c1fc670ca', '77eca4746971e75c1fc670cf'],
|
|
234
|
+
*/
|
|
235
|
+
service.actionableScopes = function (
|
|
236
|
+
user,
|
|
237
|
+
action,
|
|
238
|
+
definition,
|
|
239
|
+
type,
|
|
240
|
+
options,
|
|
241
|
+
) {
|
|
242
|
+
options = options || {};
|
|
243
|
+
|
|
244
|
+
/////////////////////////
|
|
245
|
+
|
|
246
|
+
var validScopes = [];
|
|
247
|
+
|
|
248
|
+
if (user?.userType == "administrator") {
|
|
249
|
+
validScopes = service.allUserScopes(user, options);
|
|
250
|
+
} else {
|
|
251
|
+
var permissionsLookup = service.hashPermissions(user);
|
|
252
|
+
|
|
253
|
+
var checkTypeName = definition || type;
|
|
254
|
+
if (!checkTypeName) {
|
|
255
|
+
return validScopes;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
let definitionScopes = !definition
|
|
259
|
+
? []
|
|
260
|
+
: permissionsLookup[`${definition}.${action}`] || [];
|
|
261
|
+
let typeScopes = !type
|
|
262
|
+
? []
|
|
263
|
+
: permissionsLookup[`${type}.${action}`] || [];
|
|
264
|
+
|
|
265
|
+
validScopes = [...definitionScopes, ...typeScopes];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/////////////////////////
|
|
269
|
+
|
|
270
|
+
return validScopes || [];
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
///////////////////////////////////////////////
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @alias access.isOwner
|
|
277
|
+
* @description Return whether or not a user is considered an Owner of a specified item
|
|
278
|
+
* @param {Object} user The user to check
|
|
279
|
+
* @param {Object} item The item
|
|
280
|
+
* @example
|
|
281
|
+
* const user = sdk.auth.getCurrentUser();
|
|
282
|
+
* const item = {title:'A piece of content', meta:{personaAuthor:'61eca4746971e75c1fc670ca'}, ...}
|
|
283
|
+
*
|
|
284
|
+
* // Returns true if the user owns the item
|
|
285
|
+
* const isTheOwner = sdk.access.isOwner(user, item);
|
|
286
|
+
*/
|
|
287
|
+
service.isOwner = function (user, item) {
|
|
288
|
+
var userID = QikCore.utils.id(user);
|
|
289
|
+
var personaID = QikCore.utils.id(user?.persona);
|
|
290
|
+
|
|
291
|
+
var metaObject = item.meta;
|
|
292
|
+
if (!metaObject) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/////////////////////////////////////////////
|
|
297
|
+
|
|
298
|
+
var userOwners = metaObject.userOwners || [];
|
|
299
|
+
|
|
300
|
+
var users = QikCore.utils.ids([...userOwners, metaObject.userAuthor]);
|
|
301
|
+
var userHash = QikCore.utils.hash(users);
|
|
302
|
+
|
|
303
|
+
if (userHash[userID]) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/////////////////////////////////////////////
|
|
308
|
+
|
|
309
|
+
var personaOwners = metaObject.personaOwners || [];
|
|
310
|
+
|
|
311
|
+
var personas = QikCore.utils.ids([
|
|
312
|
+
...personaOwners,
|
|
313
|
+
metaObject.personaAuthor,
|
|
314
|
+
]);
|
|
315
|
+
var personaHash = QikCore.utils.hash(personas);
|
|
316
|
+
|
|
317
|
+
if (personaHash[personaID]) {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const isAssignee = service.isAssignee(user, item);
|
|
322
|
+
|
|
323
|
+
return isAssignee;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @alias access.isAssignee
|
|
328
|
+
* @description Return whether or not a user is an assignee of a specified item
|
|
329
|
+
* @param {Object} user The user to check
|
|
330
|
+
* @param {Object} item The item
|
|
331
|
+
* @example
|
|
332
|
+
* const user = sdk.auth.getCurrentUser();
|
|
333
|
+
* const item = {title:'A workflow card', assignees:['61eca4746971e75c1fc670ca'], ...}
|
|
334
|
+
*
|
|
335
|
+
* // Returns true if the user owns the item
|
|
336
|
+
* const isAssignee = sdk.access.isAssignee(user, item);
|
|
337
|
+
*/
|
|
338
|
+
service.isAssignee = function (user, contentItem) {
|
|
339
|
+
// Check the user profile ids
|
|
340
|
+
const profileIDs = QikCore.utils.ids(user?.profiles);
|
|
341
|
+
if (!profileIDs.length) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Check if the content item has assignees set
|
|
346
|
+
const assigneeIDs = QikCore.utils.ids(contentItem.assignees);
|
|
347
|
+
|
|
348
|
+
if (!assigneeIDs.length) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Return the intersection of assignees and profile ids
|
|
353
|
+
const set = new Set(assigneeIDs);
|
|
354
|
+
const matches = profileIDs.filter((item) => set.has(item));
|
|
355
|
+
const isAssignee = !!matches.length;
|
|
356
|
+
|
|
357
|
+
return isAssignee;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
///////////////////////////////////////////////
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @alias access.allPermissions
|
|
364
|
+
* @description Returns an array of all permissions a given user has access to
|
|
365
|
+
* @param {Object} user The user to check
|
|
366
|
+
* @example
|
|
367
|
+
* const user = sdk.auth.getCurrentUser();
|
|
368
|
+
* const permissions = sdk.access.allPermissions(user);
|
|
369
|
+
*
|
|
370
|
+
* // Returns
|
|
371
|
+
* ['image.viewany', 'testimonial.viewany', 'testimonial.viewfield.title', ...]
|
|
372
|
+
*/
|
|
373
|
+
service.allPermissions = function (user) {
|
|
374
|
+
var allPermissions = Object.values(user?.permissions || {})
|
|
375
|
+
.map(function (permissionScope) {
|
|
376
|
+
return permissionScope.permissions;
|
|
377
|
+
})
|
|
378
|
+
.flat();
|
|
379
|
+
|
|
380
|
+
return allPermissions;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
///////////////////////////////////////////////
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @alias access.allPermissionTypes
|
|
387
|
+
* @description Returns an array of content types a given user has permission to interact with
|
|
388
|
+
* @param {Object} user The user to check
|
|
389
|
+
* @param {Boolean} asHash Whether to retrieve the result as a keyed object hash, by default
|
|
390
|
+
* the response will be an array
|
|
391
|
+
* @example
|
|
392
|
+
* const user = sdk.auth.getCurrentUser();
|
|
393
|
+
*
|
|
394
|
+
* // Returns ['image', 'testimonial']
|
|
395
|
+
* const types = sdk.access.allPermissionTypes(user);
|
|
396
|
+
*
|
|
397
|
+
* // Returns {image:true, testimonial:true}
|
|
398
|
+
* const types = sdk.access.allPermissionTypes(user, true);
|
|
399
|
+
*/
|
|
400
|
+
service.allPermissionTypes = function (user, asHash) {
|
|
401
|
+
if (asHash) {
|
|
402
|
+
return service.allPermissions(user).reduce(function (set, string) {
|
|
403
|
+
var type = string.split(".")[0];
|
|
404
|
+
set[type] = true;
|
|
405
|
+
return set;
|
|
406
|
+
}, {});
|
|
407
|
+
} else {
|
|
408
|
+
return service.allPermissions(user).map(function (string) {
|
|
409
|
+
return string.split(".")[0];
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
///////////////////////////////////////////////
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @alias access.canKnowOf
|
|
418
|
+
* @description Checks if a user has any permissions relating to a specified type of content
|
|
419
|
+
* @param {Object} user The user to check
|
|
420
|
+
* @param {String} typeKey The type or definition to check
|
|
421
|
+
* @param {Object} options Additional options and parameters
|
|
422
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
423
|
+
* @example
|
|
424
|
+
* const user = sdk.auth.getCurrentUser();
|
|
425
|
+
* const canAccessImageSection = sdk.access.canKnowOf(user, 'image');
|
|
426
|
+
* const canAccessCustomerUploadSection = sdk.access.canKnowOf(user, 'customerUpload');
|
|
427
|
+
*/
|
|
428
|
+
service.canKnowOf = function (user, typeKey, options) {
|
|
429
|
+
options = options || {};
|
|
430
|
+
options.cache = options.cache || {};
|
|
431
|
+
|
|
432
|
+
//Let us know if there are any permissions for this user
|
|
433
|
+
return service.allPermissionTypes(user, true)[typeKey];
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
///////////////////////////////////////////////
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @alias access.checkActionAccess
|
|
440
|
+
* @description Helpful function for checking whether a given user has access to do a given action on a specified item
|
|
441
|
+
* @param {Object} user The user to check
|
|
442
|
+
* @param {Object} item The item to check
|
|
443
|
+
* @param {String} ANY_ACTION The 'any' action to check
|
|
444
|
+
* @param {String} OWN_ACTION The 'owned' action to check
|
|
445
|
+
* @param {Object} options Additional options and parameters
|
|
446
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
447
|
+
* @example
|
|
448
|
+
* const user = sdk.auth.getCurrentUser();
|
|
449
|
+
* const canEditItem = sdk.access.checkActionAccess(user, {_id:'61eca4746971e75c1fc670ca', meta:{...}}, 'editany', 'editown');
|
|
450
|
+
* const canViewItem = sdk.access.checkActionAccess(user, {_id:'61eca4746971e75c1fc670ca', meta:{...}}, 'viewany', 'viewown');
|
|
451
|
+
*
|
|
452
|
+
* // Example of looping through a large array of items
|
|
453
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
454
|
+
*
|
|
455
|
+
* // Create an in memory cache object outside of the loop
|
|
456
|
+
* const cache = {}
|
|
457
|
+
*
|
|
458
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
459
|
+
* return sdk.access.checkActionAccess(user, item, 'editany', 'editown', {cache});
|
|
460
|
+
* })
|
|
461
|
+
*/
|
|
462
|
+
service.checkActionAccess = function (
|
|
463
|
+
user,
|
|
464
|
+
item,
|
|
465
|
+
ANY_ACTION,
|
|
466
|
+
OWN_ACTION,
|
|
467
|
+
options,
|
|
468
|
+
) {
|
|
469
|
+
options = options || {};
|
|
470
|
+
options.cache = options.cache || {};
|
|
471
|
+
|
|
472
|
+
//Allow everything if we're a super user
|
|
473
|
+
if (service.isAdministrator(user)) {
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
//////////////////////////////////
|
|
478
|
+
|
|
479
|
+
var type = item.meta?.type;
|
|
480
|
+
var definition = item.meta?.definition || type;
|
|
481
|
+
|
|
482
|
+
if (!definition) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
//////////////////////////////////
|
|
487
|
+
|
|
488
|
+
//The user should be able to list any scopes that they have
|
|
489
|
+
//permission to do things in.
|
|
490
|
+
if (ANY_ACTION == "listany" || OWN_ACTION == "listown") {
|
|
491
|
+
if (type === "scope") {
|
|
492
|
+
var itemID = QikCore.utils.id(item);
|
|
493
|
+
return !!user.permissions[itemID];
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
//////////////////////////////////
|
|
498
|
+
|
|
499
|
+
var itemScopes = QikCore.utils.ids(item.meta.scopes || []);
|
|
500
|
+
|
|
501
|
+
//Scopes don't have meta.scopes, instead use the scope's
|
|
502
|
+
//path (ancestors) plus the scope's own ID
|
|
503
|
+
if (type === "scope") {
|
|
504
|
+
itemScopes = [
|
|
505
|
+
...QikCore.utils.ids(item.path || []),
|
|
506
|
+
QikCore.utils.id(item),
|
|
507
|
+
];
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
//////////////////////////////////
|
|
511
|
+
|
|
512
|
+
var actionAnyScopesHash;
|
|
513
|
+
var anyCacheKey = `access-${user?.cacheKey}-${ANY_ACTION}-${definition}-${type}`;
|
|
514
|
+
|
|
515
|
+
if (options.cache[anyCacheKey]) {
|
|
516
|
+
actionAnyScopesHash = options.cache[anyCacheKey];
|
|
517
|
+
} else {
|
|
518
|
+
//Check if we can action this type of thing in any scopes
|
|
519
|
+
var actionAnyScopes = QikCore.utils.ids(
|
|
520
|
+
service.actionableScopes(user, ANY_ACTION, definition, type, options),
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
//Get a fash hash of the scopes
|
|
524
|
+
actionAnyScopesHash = QikCore.utils.hash(actionAnyScopes);
|
|
525
|
+
options.cache[anyCacheKey] = actionAnyScopesHash;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
//////////////////////////////////
|
|
529
|
+
|
|
530
|
+
//If we have data about what they can do
|
|
531
|
+
if (actionAnyScopesHash) {
|
|
532
|
+
//Check if the item is in any of the scopes the user can access
|
|
533
|
+
var isInAnyScopes = itemScopes.some(function (scopeID) {
|
|
534
|
+
return actionAnyScopesHash[scopeID];
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
if (isInAnyScopes) {
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
//////////////////////////////////
|
|
543
|
+
|
|
544
|
+
//Check if the user owns this content
|
|
545
|
+
var isOwner = service.isOwner(user, item);
|
|
546
|
+
|
|
547
|
+
//If the user is the owner
|
|
548
|
+
if (isOwner) {
|
|
549
|
+
var actionOwnScopesHash;
|
|
550
|
+
var ownCacheKey = `access-${user?.cacheKey}-${OWN_ACTION}-${definition}-${type}`;
|
|
551
|
+
|
|
552
|
+
if (options.cache[ownCacheKey]) {
|
|
553
|
+
actionOwnScopesHash = options.cache[ownCacheKey];
|
|
554
|
+
} else {
|
|
555
|
+
//Check if we can action this type of thing in any scopes
|
|
556
|
+
var actionOwnScopes = QikCore.utils.ids(
|
|
557
|
+
service.actionableScopes(user, OWN_ACTION, definition, type, options),
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
//Get a fash hash of the scopes
|
|
561
|
+
actionOwnScopesHash = QikCore.utils.hash(actionOwnScopes);
|
|
562
|
+
options.cache[ownCacheKey] = actionOwnScopesHash;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
//If we have data about what they can do
|
|
566
|
+
if (actionOwnScopesHash) {
|
|
567
|
+
//Check if the item is in any of the scopes the user can access
|
|
568
|
+
var isInOwnScopes = itemScopes.some(function (scopeID) {
|
|
569
|
+
return actionOwnScopesHash[scopeID];
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
if (isInOwnScopes) {
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
//////////////////////////////////
|
|
579
|
+
|
|
580
|
+
//No access by default
|
|
581
|
+
return false;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
///////////////////////////////////////////////
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* @alias access.has
|
|
588
|
+
* @description Helpful function for checking whether a given user has a specified permission
|
|
589
|
+
* @param {Object} user The user to check
|
|
590
|
+
* @param {String} permission The permission the user may have been granted
|
|
591
|
+
* @example
|
|
592
|
+
* const user = sdk.auth.getCurrentUser();
|
|
593
|
+
* const isAllowedToCreateItems = sdk.access.has(user, 'video.create');
|
|
594
|
+
*/
|
|
595
|
+
service.has = function (user, permission) {
|
|
596
|
+
//Allow everything if we're a super user
|
|
597
|
+
if (service.isAdministrator(user)) {
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
var permissionsLookup = service.hashPermissions(user);
|
|
602
|
+
return permissionsLookup[permission];
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
///////////////////////////////////////////////
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* @alias access.canCreate
|
|
609
|
+
* @description Helpful function for checking whether a given user can create a specified type of item
|
|
610
|
+
* @param {Object} user The user to check
|
|
611
|
+
* @param {String} definition The defined type key
|
|
612
|
+
* @param {String} type The basic type key
|
|
613
|
+
* @param {Object} options Additional options and parameters
|
|
614
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
615
|
+
* @example
|
|
616
|
+
* const user = sdk.auth.getCurrentUser();
|
|
617
|
+
* const userCanCreateShortFilms = sdk.access.canCreate(user, 'shortFilm', 'video');
|
|
618
|
+
*/
|
|
619
|
+
service.canCreate = function (user, definition, type, options) {
|
|
620
|
+
options = options || {};
|
|
621
|
+
options.cache = options.cache || {};
|
|
622
|
+
|
|
623
|
+
//Allow everything if we're a super user
|
|
624
|
+
if (service.isAdministrator(user)) {
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
var createableScopes = service.actionableScopes(
|
|
629
|
+
user,
|
|
630
|
+
"create",
|
|
631
|
+
definition,
|
|
632
|
+
type,
|
|
633
|
+
);
|
|
634
|
+
return createableScopes.length;
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
///////////////////////////////////////////////
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* @alias access.canListItem
|
|
641
|
+
* @description Helpful function for checking whether a given user can list a specified item
|
|
642
|
+
* @param {Object} user The user to check
|
|
643
|
+
* @param {Object} item The item to check
|
|
644
|
+
* @param {Object} options Additional options and parameters
|
|
645
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
646
|
+
* @example
|
|
647
|
+
* const user = sdk.auth.getCurrentUser();
|
|
648
|
+
*
|
|
649
|
+
* // Example of looping through a large array of items
|
|
650
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
651
|
+
*
|
|
652
|
+
* // Create an in memory cache object outside of the loop
|
|
653
|
+
* const cache = {}
|
|
654
|
+
*
|
|
655
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
656
|
+
* return sdk.access.canListItem(user, item, {cache});
|
|
657
|
+
* })
|
|
658
|
+
*/
|
|
659
|
+
service.canListItem = function (user, item, options) {
|
|
660
|
+
options = options || {};
|
|
661
|
+
options.cache = options.cache || {};
|
|
662
|
+
|
|
663
|
+
//Check if we can list the item
|
|
664
|
+
var canList = service.checkActionAccess(
|
|
665
|
+
user,
|
|
666
|
+
item,
|
|
667
|
+
"listany",
|
|
668
|
+
"listown",
|
|
669
|
+
options,
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
if (canList) {
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
//If we can view the item then we should be able to list it also
|
|
677
|
+
var canView = service.canViewItem(user, item, options);
|
|
678
|
+
if (canView) {
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
return false;
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
///////////////////////////////////////////////
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* @alias access.canViewItem
|
|
689
|
+
* @description Helpful function for checking whether a given user can view a specified item
|
|
690
|
+
* @param {Object} user The user to check
|
|
691
|
+
* @param {Object} item The item to check
|
|
692
|
+
* @param {Object} options Additional options and parameters
|
|
693
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
694
|
+
* @example
|
|
695
|
+
* const user = sdk.auth.getCurrentUser();
|
|
696
|
+
*
|
|
697
|
+
* // Example of looping through a large array of items
|
|
698
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
699
|
+
*
|
|
700
|
+
* // Create an in memory cache object outside of the loop
|
|
701
|
+
* const cache = {}
|
|
702
|
+
*
|
|
703
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
704
|
+
* return sdk.access.canViewItem(user, item, {cache});
|
|
705
|
+
* })
|
|
706
|
+
*/
|
|
707
|
+
service.canViewItem = function (user, item, options) {
|
|
708
|
+
options = options || {};
|
|
709
|
+
options.cache = options.cache || {};
|
|
710
|
+
|
|
711
|
+
//Check if we can view the item
|
|
712
|
+
var canView = service.checkActionAccess(
|
|
713
|
+
user,
|
|
714
|
+
item,
|
|
715
|
+
"viewany",
|
|
716
|
+
"viewOwn",
|
|
717
|
+
options,
|
|
718
|
+
);
|
|
719
|
+
if (canView) {
|
|
720
|
+
return true;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
//If we can edit the item then we should be able to view it also
|
|
724
|
+
var canEdit = service.canEditItem(user, item, options);
|
|
725
|
+
if (canEdit) {
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
return false;
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
///////////////////////////////////////////////
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @alias access.canEditItem
|
|
736
|
+
* @description Helpful function for checking whether a given user can edit a specified item
|
|
737
|
+
* @param {Object} user The user to check
|
|
738
|
+
* @param {Object} item The item to check
|
|
739
|
+
* @param {Object} options Additional options and parameters
|
|
740
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
741
|
+
* @example
|
|
742
|
+
* const user = sdk.auth.getCurrentUser();
|
|
743
|
+
*
|
|
744
|
+
* // Example of looping through a large array of items
|
|
745
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
746
|
+
*
|
|
747
|
+
* // Create an in memory cache object outside of the loop
|
|
748
|
+
* const cache = {}
|
|
749
|
+
*
|
|
750
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
751
|
+
* return sdk.access.canEditItem(user, item, {cache});
|
|
752
|
+
* })
|
|
753
|
+
*/
|
|
754
|
+
service.canEditItem = function (user, item, options) {
|
|
755
|
+
options = options || {};
|
|
756
|
+
options.cache = options.cache || {};
|
|
757
|
+
|
|
758
|
+
var allowed = service.checkActionAccess(
|
|
759
|
+
user,
|
|
760
|
+
item,
|
|
761
|
+
"editany",
|
|
762
|
+
"editown",
|
|
763
|
+
options,
|
|
764
|
+
);
|
|
765
|
+
|
|
766
|
+
return allowed;
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
///////////////////////////////////////////////
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* @alias access.canDeleteItem
|
|
773
|
+
* @description Helpful function for checking whether a given user can delete a specified item
|
|
774
|
+
* @param {Object} user The user to check
|
|
775
|
+
* @param {Object} item The item to check
|
|
776
|
+
* @param {Object} options Additional options and parameters
|
|
777
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
778
|
+
* @example
|
|
779
|
+
* const user = sdk.auth.getCurrentUser();
|
|
780
|
+
*
|
|
781
|
+
* // Example of looping through a large array of items
|
|
782
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
783
|
+
*
|
|
784
|
+
* // Create an in memory cache object outside of the loop
|
|
785
|
+
* const cache = {}
|
|
786
|
+
*
|
|
787
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
788
|
+
* return sdk.access.canDeleteItem(user, item, {cache});
|
|
789
|
+
* })
|
|
790
|
+
*/
|
|
791
|
+
service.canDeleteItem = function (user, item, options) {
|
|
792
|
+
options = options || {};
|
|
793
|
+
options.cache = options.cache || {};
|
|
794
|
+
|
|
795
|
+
return service.checkActionAccess(
|
|
796
|
+
user,
|
|
797
|
+
item,
|
|
798
|
+
"deleteany",
|
|
799
|
+
"deleteown",
|
|
800
|
+
options,
|
|
801
|
+
);
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
///////////////////////////////////////////////
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* @alias access.canRestoreItem
|
|
808
|
+
* @description Helpful function for checking whether a given user can restore a specified item
|
|
809
|
+
* @param {Object} user The user to check
|
|
810
|
+
* @param {Object} item The item to check
|
|
811
|
+
* @param {Object} options Additional options and parameters
|
|
812
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
813
|
+
* @example
|
|
814
|
+
* const user = sdk.auth.getCurrentUser();
|
|
815
|
+
*
|
|
816
|
+
* // Example of looping through a large array of items
|
|
817
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
818
|
+
*
|
|
819
|
+
* // Create an in memory cache object outside of the loop
|
|
820
|
+
* const cache = {}
|
|
821
|
+
*
|
|
822
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
823
|
+
* return sdk.access.canRestoreItem(user, item, {cache});
|
|
824
|
+
* })
|
|
825
|
+
*/
|
|
826
|
+
service.canRestoreItem = function (user, item, options) {
|
|
827
|
+
options = options || {};
|
|
828
|
+
options.cache = options.cache || {};
|
|
829
|
+
|
|
830
|
+
return service.checkActionAccess(
|
|
831
|
+
user,
|
|
832
|
+
item,
|
|
833
|
+
"restoreany",
|
|
834
|
+
"restoreown",
|
|
835
|
+
options,
|
|
836
|
+
);
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
///////////////////////////////////////////////
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* @alias access.canEraseItem
|
|
843
|
+
* @description Helpful function for checking whether a given user can erase a specified item
|
|
844
|
+
* @param {Object} user The user to check
|
|
845
|
+
* @param {Object} item The item to check
|
|
846
|
+
* @param {Object} options Additional options and parameters
|
|
847
|
+
* @param {Object} options.cache Provide an existing object to use as an in memory cache, can be useful to increase performance if running this function in a large for/while loop
|
|
848
|
+
* @example
|
|
849
|
+
* const user = sdk.auth.getCurrentUser();
|
|
850
|
+
*
|
|
851
|
+
* // Example of looping through a large array of items
|
|
852
|
+
* const largeArrayOfItems = [{_id:'...', title...}, {_id:'...', title...}...]
|
|
853
|
+
*
|
|
854
|
+
* // Create an in memory cache object outside of the loop
|
|
855
|
+
* const cache = {}
|
|
856
|
+
*
|
|
857
|
+
* const filtered = largeArrayOfItems.filter(function(item) {
|
|
858
|
+
* return sdk.access.canEraseItem(user, item, {cache});
|
|
859
|
+
* })
|
|
860
|
+
*/
|
|
861
|
+
service.canEraseItem = function (user, item, options) {
|
|
862
|
+
options = options || {};
|
|
863
|
+
options.cache = options.cache || {};
|
|
864
|
+
|
|
865
|
+
return service.checkActionAccess(
|
|
866
|
+
user,
|
|
867
|
+
item,
|
|
868
|
+
"eraseany",
|
|
869
|
+
"eraseown",
|
|
870
|
+
options,
|
|
871
|
+
);
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
return service;
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
878
|
+
|
|
879
|
+
export default QikAccess;
|
|
880
|
+
</code></pre>
|
|
881
|
+
</article>
|
|
882
|
+
</section>
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
</div>
|
|
890
|
+
|
|
891
|
+
<br class="clear">
|
|
892
|
+
|
|
893
|
+
<footer>
|
|
894
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Jun 01 2026 23:37:17 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
895
|
+
</footer>
|
|
896
|
+
|
|
897
|
+
<script>prettyPrint();</script>
|
|
898
|
+
<script src="scripts/polyfill.js"></script>
|
|
899
|
+
<script src="scripts/linenumber.js"></script>
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
</body>
|
|
904
|
+
</html>
|