Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ export const APP_STATE = createRequestTypes('APP_STATE', ['FOREGROUND', 'BACKGRO
export const ENTERPRISE_MODULES = createRequestTypes('ENTERPRISE_MODULES', ['CLEAR', 'SET']);
export const ENCRYPTION = createRequestTypes('ENCRYPTION', ['INIT', 'STOP', 'DECODE_KEY', 'SET', 'SET_BANNER']);

export const PERMISSIONS = createRequestTypes('PERMISSIONS', ['SET']);
export const PERMISSIONS = createRequestTypes('PERMISSIONS', ['SET', 'UPDATE']);
7 changes: 7 additions & 0 deletions app/actions/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export function setPermissions(permissions) {
permissions
};
}

export function updatePermissions(id, roles) {
Comment thread
gerzonc marked this conversation as resolved.
Outdated
return {
type: types.PERMISSIONS.UPDATE,
payload: { id, roles }
};
}
16 changes: 16 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import UserPreferences from './userPreferences';
import { Encryption } from './encryption';
import EventEmitter from '../utils/events';
import { sanitizeLikeString } from './database/utils';
import { updatePermissions } from '../actions/permissions';

const TOKEN_KEY = 'reactnativemeteor_usertoken';
const CURRENT_SERVER = 'currentServer';
Expand Down Expand Up @@ -292,6 +293,21 @@ const RocketChat = {
} catch {
// We can't create a new record since we don't receive the user._id
}
} else if (/permissions-changed/.test(eventName)) {
const { _id, roles } = ddpMessage.fields.args[1];
const db = database.active;
const permissionsCollection = db.get('permissions');
try {
const permissionsRecord = await permissionsCollection.find(_id);
await db.action(async() => {
await permissionsRecord.update((u) => {
u.roles = roles;
});
});
reduxStore.dispatch(updatePermissions(_id, roles));
} catch (err) {
//
}
} else if (/Users:NameChanged/.test(eventName)) {
const userNameChanged = ddpMessage.fields.args[0];
const db = database.active;
Expand Down
5 changes: 5 additions & 0 deletions app/reducers/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export default function permissions(state = initialState, action) {
switch (action.type) {
case PERMISSIONS.SET:
return action.permissions;
case PERMISSIONS.UPDATE:
return {
...state,
[action.payload.id]: action.payload.roles
};
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
};

const fetchPermissions = function* fetchPermissions() {
RocketChat.subscribe('stream-notify-logged', 'permissions-changed');
Comment thread
gerzonc marked this conversation as resolved.
Outdated
yield RocketChat.getPermissions();
};

Expand Down