2018-04-24 19:34:03 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
2018-10-15 20:22:42 +00:00
|
|
|
import * as SDK from '@rocket.chat/sdk';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
import database from '../realm';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../utils/log';
|
2018-06-18 13:30:36 +00:00
|
|
|
import defaultPermissions from '../../constants/permissions';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
export default async function() {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2018-12-05 20:52:08 +00:00
|
|
|
const result = await SDK.api.get('permissions.list');
|
|
|
|
|
|
|
|
if (!result.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const permissions = result.permissions.filter(permission => defaultPermissions.includes(permission._id));
|
2018-06-18 13:30:36 +00:00
|
|
|
permissions
|
|
|
|
.map((permission) => {
|
|
|
|
permission._updatedAt = new Date();
|
|
|
|
permission.roles = permission.roles.map(role => ({ value: role }));
|
|
|
|
return permission;
|
|
|
|
});
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
InteractionManager.runAfterInteractions(
|
2018-10-15 20:22:42 +00:00
|
|
|
() => database.write(() => permissions.forEach((permission) => {
|
|
|
|
try {
|
|
|
|
database.create('permissions', permission, true);
|
|
|
|
} catch (e) {
|
|
|
|
log('getPermissions create', e);
|
|
|
|
}
|
|
|
|
}))
|
2018-09-25 19:28:42 +00:00
|
|
|
);
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
log('getPermissions', e);
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|