Skip to content

Commit 7cd1776

Browse files
camdagr8Cam Tullos
andauthored
Bugfix/actinium core (#20)
* no message * fixed users lib where it was killing the memory if there were too many users. * Added user-roles cloud function to deal with the loss of roles being automatically appended to the user object on fetch. --------- Co-authored-by: Cam Tullos <[email protected]>
1 parent 766b25c commit 7cd1776

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

actinium_modules/@atomic-reactor/actinium-users/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"type": "module",
99
"name": "@atomic-reactor/actinium-users",
10-
"version": "5.0.2",
10+
"version": "5.0.4",
1111
"description": "Actinium core plugin",
1212
"main": "index.js",
1313
"scripts": {

actinium_modules/@atomic-reactor/actinium-users/plugin.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const MOD = () => {
4040
return objects;
4141
}
4242

43+
/*
44+
* ---------------------------------------------------------------------------------------------------
45+
// TODO: Figure out a better way to implement this w/o iterating over the objects on every find
46+
* ---------------------------------------------------------------------------------------------------
4347
for (let i = 0; i < objects.length; i++) {
4448
let user = objects[i];
4549
@@ -52,6 +56,9 @@ const MOD = () => {
5256
user.set('capabilities', capabilities);
5357
objects[i] = user;
5458
}
59+
*/
60+
61+
await Actinium.Hook.run('user-fetch', objects);
5562

5663
return Promise.resolve(objects);
5764
};
@@ -77,6 +84,23 @@ const MOD = () => {
7784
return Actinium.User.retrieve(req.params, options);
7885
};
7986

87+
const roles = async (req) => {
88+
if (!req.user) return [];
89+
90+
const options = { useMaskterKey: true, json: false };
91+
const qry = new Actinium.Query(Actinium.Role);
92+
qry.equalTo('users', req.user);
93+
qry.descending('level');
94+
95+
const results = await qry.find(options);
96+
97+
return results.reduce((roles, item) => {
98+
roles['anonymous'] = 0;
99+
roles[item.get('name')] = item.get('level');
100+
return roles;
101+
}, {});
102+
};
103+
80104
const save = (req) => {
81105
const options = CloudRunOptions(req);
82106
return Actinium.User.save(req.params, options);
@@ -244,6 +268,8 @@ const MOD = () => {
244268

245269
Actinium.Cloud.define(PLUGIN.ID, 'user-retrieve', retrieve);
246270

271+
Actinium.Cloud.define(PLUGIN.ID, 'user-roles', roles);
272+
247273
Actinium.Cloud.define(PLUGIN.ID, 'user-save', save);
248274

249275
Actinium.Cloud.define(PLUGIN.ID, 'user-trash', trash);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/documentation/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Hooks are synchronous and will execute in the order they are registered unless t
8080
* @apiParam (Hooks) user-before-find Triggered when the `user-find` cloud function is called.
8181
* @apiParam (Hooks) user-before-login Triggered before a sign in attempt.
8282
* @apiParam (Hooks) user-before-save Triggered after a Parse.User object is saved.
83-
* @apiParam (Hooks) user-fetch Triggered when a user is fetched from the server. The fetched `Parse.User` object is passed to the hook.
83+
* @apiParam (Hooks) user-fetch Triggered when a users are fetched from the server. The fetched `Parse.User` objects are passed to the hook as an Array.
8484
* @apiParam (Hooks) warning Triggered when the startup warnings are logged.
8585
*/
8686

0 commit comments

Comments
 (0)