Commit fe514a05 by GD-A-150752

update-password

parent c757f60d
......@@ -16,26 +16,26 @@ export const seedDB = async () => {
// Roles
await Promise.all([
Roles.insert({
Title: 'Admin',
Permissions: allPermissions,
Description: '',
title: 'Admin',
permissions: allPermissions,
description: '',
}).toPromise(),
Roles.insert({
Title: 'User',
Permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
Description: '',
title: 'User',
permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
description: '',
}).toPromise(),
Roles.insert({
Title: 'Blocked',
Permissions: [],
Description: '',
title: 'Blocked',
permissions: [],
description: '',
}),
]);
} else {
// Update Roles Permissions
await Promise.all([
Roles
.update({ Title: 'Admin' }, { $set: { Permissions: allPermissions } })
.update({ title: 'Admin' }, { $set: { permissions: allPermissions } })
.toPromise(),
]);
}
......@@ -49,10 +49,8 @@ export const seedDB = async () => {
password: 'admin',
email: 'ali.arshad@vqode.com',
profile: {
Role: Roles.findOne({ Title: 'Admin' })._id, // admin role id
FirstName: 'Admin',
LastName: 'User',
Status: 'ACTIVE',
name: 'Admin User',
role: Roles.findOne({ title: 'Admin' })._id, // admin role id
},
});
}
......
......@@ -14,7 +14,7 @@ Meteor.startup(() => {
Accounts.validateLoginAttempt((data): boolean => {
const user: Meteor.User = data.user;
return user && user.profile.Role
return user && user.profile.role
&& UtilsService.hasPermissionOfUser(user, PERMISSIONS.CAN_LOGIN);
});
......
......@@ -15,7 +15,7 @@ Meteor.methods({
},
registerUser(user: any): string {
const defaultRole = Roles.findOne({ Title: user.role });
const defaultRole = Roles.findOne({ title: user.role });
if (!Accounts.findUserByEmail(user.email)) {
const userObj = {
......@@ -23,8 +23,8 @@ Meteor.methods({
password: user.password,
username: user.username,
profile: {
Name: user.name,
Role: defaultRole._id,
name: user.name,
role: defaultRole._id,
},
};
return Accounts.createUser(userObj);
......@@ -36,11 +36,12 @@ Meteor.methods({
if (!UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_OWN_USER)) {
throw new Meteor.Error(403, 'Forbidden.');
}
if (user._id) {
const updateObj = { $set: { profile: user.profile } };
if (user.profile.Email) {
updateObj.$set['emails.0.address'] = user.profile.Email;
if (user.password) {
Accounts.setPassword(user._id, user.password);
}
const updateObj = { $set: { profile: user.profile } };
return Meteor.users.update(user._id, updateObj);
}
......
export interface Role {
_id?: string;
Title: string;
Permissions: string[];
Description: string;
title: string;
permissions: string[];
description: string;
}
......@@ -22,7 +22,7 @@ publishComposite('usersList', (filters = {}) => {
children: [
{
find(user): any {
return Roles.find({ _id: user.profile.Role });
return Roles.find({ _id: user.profile.role });
},
},
],
......
......@@ -8,30 +8,30 @@ export class UtilsService {
static getLoggedInUserPermissions(): string[] {
const usr: Meteor.User = Meteor.user();
const role = Roles.findOne(usr.profile.Role);
const role = Roles.findOne(usr.profile.role);
return role.Permissions;
return role.permissions;
}
static hasPermission(permissions: string | string[]): boolean {
const usr: Meteor.User = Meteor.user();
if (usr) {
const role = Roles.findOne(usr.profile.Role);
const role = Roles.findOne(usr.profile.role);
if (typeof permissions === 'string') {
return role.Permissions.indexOf(permissions) !== -1;
return role.permissions.indexOf(permissions) !== -1;
}
return permissions.every(p => role.Permissions.indexOf(p) !== -1);
return permissions.every(p => role.permissions.indexOf(p) !== -1);
}
return false;
}
static hasPermissionOfUser(user: Meteor.User, permission: string): boolean {
const role = Roles.findOne(user.profile.Role);
const role = Roles.findOne(user.profile.role);
return role.Permissions.indexOf(permission) !== -1;
return role.permissions.indexOf(permission) !== -1;
}
static uploadToAWS(base64, key): Observable<any> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment