2019-09-16 20:26:32 +00:00
|
|
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
2021-02-25 16:41:44 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2021-02-01 17:18:55 +00:00
|
|
|
import orderBy from 'lodash/orderBy';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2021-03-18 13:33:35 +00:00
|
|
|
import { compareServerVersion, methods } from '../utils';
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../database';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../utils/log';
|
2019-04-26 20:54:58 +00:00
|
|
|
import reduxStore from '../createStore';
|
2021-07-01 13:57:23 +00:00
|
|
|
import RocketChat from '../rocketchat';
|
2021-02-25 16:41:44 +00:00
|
|
|
import { setPermissions as setPermissionsAction } from '../../actions/permissions';
|
2021-09-13 20:41:05 +00:00
|
|
|
import protectedFunction from './helpers/protectedFunction';
|
2021-02-25 16:41:44 +00:00
|
|
|
|
|
|
|
const PERMISSIONS = [
|
|
|
|
'add-user-to-any-c-room',
|
|
|
|
'add-user-to-any-p-room',
|
|
|
|
'add-user-to-joined-room',
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
'add-team-channel',
|
2021-02-25 16:41:44 +00:00
|
|
|
'archive-room',
|
|
|
|
'auto-translate',
|
|
|
|
'create-invite-links',
|
[NEW] Convert/Move Channel to Team (#3164)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Added deleteTeam function
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update index.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Update rocketchat.js
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Update RoomActionsView
* Update en.json
* updated deleteTeam function and permissions
* Added showConfirmationAlert
* Added string translations for teams
* Fix permission
* Added moveChannelToTeam and convertToTeam functionality
* Fix SelectListView RadioButton
* Fix moveToTeam
* Added searchBar to SelectListVIew
* Update RoomView , SelectListVIew and string translation for error
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-06-02 13:44:19 +00:00
|
|
|
'create-team',
|
2021-02-25 16:41:44 +00:00
|
|
|
'delete-c',
|
|
|
|
'delete-message',
|
|
|
|
'delete-p',
|
[NEW] Delete Teams (#3123)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Added deleteTeam function
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update index.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Update rocketchat.js
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Update RoomActionsView
* Update en.json
* updated deleteTeam function and permissions
* Added showConfirmationAlert
* Added string translations for teams
* Fix permission
* Minor tweaks
* Typo
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-28 14:22:41 +00:00
|
|
|
'delete-team',
|
2021-02-25 16:41:44 +00:00
|
|
|
'edit-message',
|
|
|
|
'edit-room',
|
[NEW] Remove member from team (#3117)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Added confirmationAlert for missing permissions case
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-26 21:01:06 +00:00
|
|
|
'edit-team-member',
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
'edit-team-channel',
|
2021-02-25 16:41:44 +00:00
|
|
|
'force-delete-message',
|
|
|
|
'mute-user',
|
|
|
|
'pin-message',
|
|
|
|
'post-readonly',
|
|
|
|
'remove-user',
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
'remove-team-channel',
|
2021-02-25 16:41:44 +00:00
|
|
|
'set-leader',
|
|
|
|
'set-moderator',
|
|
|
|
'set-owner',
|
|
|
|
'set-react-when-readonly',
|
|
|
|
'set-readonly',
|
|
|
|
'toggle-room-e2e-encryption',
|
|
|
|
'transfer-livechat-guest',
|
|
|
|
'unarchive-room',
|
|
|
|
'view-broadcast-member-list',
|
|
|
|
'view-privileged-setting',
|
|
|
|
'view-room-administration',
|
|
|
|
'view-statistics',
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
'view-user-administration',
|
|
|
|
'view-all-teams',
|
2021-07-09 18:46:24 +00:00
|
|
|
'view-all-team-channels',
|
2021-08-23 13:42:09 +00:00
|
|
|
'convert-team',
|
|
|
|
'edit-omnichannel-contact',
|
2021-09-22 17:29:26 +00:00
|
|
|
'edit-livechat-room-customfields',
|
|
|
|
'view-canned-responses'
|
2021-02-25 16:41:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export async function setPermissions() {
|
|
|
|
const db = database.active;
|
|
|
|
const permissionsCollection = db.collections.get('permissions');
|
|
|
|
const allPermissions = await permissionsCollection.query(Q.where('id', Q.oneOf(PERMISSIONS))).fetch();
|
|
|
|
const parsed = allPermissions.reduce((acc, item) => ({ ...acc, [item.id]: item.roles }), {});
|
|
|
|
|
|
|
|
reduxStore.dispatch(setPermissionsAction(parsed));
|
|
|
|
}
|
2019-04-26 20:54:58 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const getUpdatedSince = allRecords => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
if (!allRecords.length) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
const ordered = orderBy(
|
|
|
|
allRecords.filter(item => item._updatedAt !== null),
|
|
|
|
['_updatedAt'],
|
|
|
|
['desc']
|
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
return ordered && ordered[0]._updatedAt.toISOString();
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
return null;
|
2019-04-26 20:54:58 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const updatePermissions = async ({ update = [], remove = [], allRecords }) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!((update && update.length) || (remove && remove.length))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const db = database.active;
|
2021-02-26 16:25:51 +00:00
|
|
|
const permissionsCollection = db.get('permissions');
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
// filter permissions
|
|
|
|
let permissionsToCreate = [];
|
|
|
|
let permissionsToUpdate = [];
|
|
|
|
let permissionsToDelete = [];
|
|
|
|
|
|
|
|
// Create or update
|
|
|
|
if (update && update.length) {
|
|
|
|
permissionsToCreate = update.filter(i1 => !allRecords.find(i2 => i1._id === i2.id));
|
|
|
|
permissionsToUpdate = allRecords.filter(i1 => update.find(i2 => i1.id === i2._id));
|
2021-09-13 20:41:05 +00:00
|
|
|
permissionsToCreate = permissionsToCreate.map(permission =>
|
|
|
|
permissionsCollection.prepareCreate(
|
|
|
|
protectedFunction(p => {
|
|
|
|
p._raw = sanitizedRaw({ id: permission._id }, permissionsCollection.schema);
|
|
|
|
Object.assign(p, permission);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
permissionsToUpdate = permissionsToUpdate.map(permission => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const newPermission = update.find(p => p._id === permission.id);
|
2021-09-13 20:41:05 +00:00
|
|
|
return permission.prepareUpdate(
|
|
|
|
protectedFunction(p => {
|
|
|
|
Object.assign(p, newPermission);
|
|
|
|
})
|
|
|
|
);
|
2019-04-26 20:54:58 +00:00
|
|
|
});
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
// Delete
|
|
|
|
if (remove && remove.length) {
|
|
|
|
permissionsToDelete = allRecords.filter(i1 => remove.find(i2 => i1.id === i2._id));
|
|
|
|
permissionsToDelete = permissionsToDelete.map(permission => permission.prepareDestroyPermanently());
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const batch = [...permissionsToCreate, ...permissionsToUpdate, ...permissionsToDelete];
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
try {
|
2021-09-13 20:41:05 +00:00
|
|
|
await db.action(async () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
await db.batch(...batch);
|
|
|
|
});
|
2021-02-25 16:41:44 +00:00
|
|
|
return true;
|
2019-09-16 20:26:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2019-04-26 20:54:58 +00:00
|
|
|
};
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2021-02-25 16:41:44 +00:00
|
|
|
export function getPermissions() {
|
2021-09-13 20:41:05 +00:00
|
|
|
return new Promise(async resolve => {
|
2019-06-17 13:57:07 +00:00
|
|
|
try {
|
|
|
|
const serverVersion = reduxStore.getState().server.version;
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2021-02-26 16:25:51 +00:00
|
|
|
const permissionsCollection = db.get('permissions');
|
2019-09-16 20:26:32 +00:00
|
|
|
const allRecords = await permissionsCollection.query().fetch();
|
2021-07-01 13:57:23 +00:00
|
|
|
RocketChat.subscribe('stream-notify-logged', 'permissions-changed');
|
2019-06-17 13:57:07 +00:00
|
|
|
// if server version is lower than 0.73.0, fetches from old api
|
2021-03-18 13:33:35 +00:00
|
|
|
if (compareServerVersion(serverVersion, '0.73.0', methods.lowerThan)) {
|
2019-06-17 13:57:07 +00:00
|
|
|
// RC 0.66.0
|
|
|
|
const result = await this.sdk.get('permissions.list');
|
|
|
|
if (!result.success) {
|
|
|
|
return resolve();
|
|
|
|
}
|
2021-02-25 16:41:44 +00:00
|
|
|
const changePermissions = await updatePermissions({ update: result.permissions, allRecords });
|
|
|
|
if (changePermissions) {
|
|
|
|
setPermissions();
|
|
|
|
}
|
2021-02-23 18:36:20 +00:00
|
|
|
return resolve();
|
2019-06-17 13:57:07 +00:00
|
|
|
} else {
|
|
|
|
const params = {};
|
2021-02-25 16:41:44 +00:00
|
|
|
const updatedSince = getUpdatedSince(allRecords);
|
2019-06-17 13:57:07 +00:00
|
|
|
if (updatedSince) {
|
|
|
|
params.updatedSince = updatedSince;
|
|
|
|
}
|
|
|
|
// RC 0.73.0
|
|
|
|
const result = await this.sdk.get('permissions.listAll', params);
|
2018-06-18 13:30:36 +00:00
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
if (!result.success) {
|
|
|
|
return resolve();
|
|
|
|
}
|
2019-04-26 20:54:58 +00:00
|
|
|
|
2021-02-25 16:41:44 +00:00
|
|
|
const changePermissions = await updatePermissions({ update: result.update, remove: result.delete, allRecords });
|
|
|
|
if (changePermissions) {
|
|
|
|
setPermissions();
|
|
|
|
}
|
2021-02-23 18:36:20 +00:00
|
|
|
return resolve();
|
2019-06-17 13:57:07 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-06-17 13:57:07 +00:00
|
|
|
return resolve();
|
2019-04-26 20:54:58 +00:00
|
|
|
}
|
2019-06-17 13:57:07 +00:00
|
|
|
});
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|