Commit fe514a05 by GD-A-150752

update-password

parent c757f60d
...@@ -16,26 +16,26 @@ export const seedDB = async () => { ...@@ -16,26 +16,26 @@ export const seedDB = async () => {
// Roles // Roles
await Promise.all([ await Promise.all([
Roles.insert({ Roles.insert({
Title: 'Admin', title: 'Admin',
Permissions: allPermissions, permissions: allPermissions,
Description: '', description: '',
}).toPromise(), }).toPromise(),
Roles.insert({ Roles.insert({
Title: 'User', title: 'User',
Permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER], permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
Description: '', description: '',
}).toPromise(), }).toPromise(),
Roles.insert({ Roles.insert({
Title: 'Blocked', title: 'Blocked',
Permissions: [], permissions: [],
Description: '', description: '',
}), }),
]); ]);
} else { } else {
// Update Roles Permissions // Update Roles Permissions
await Promise.all([ await Promise.all([
Roles Roles
.update({ Title: 'Admin' }, { $set: { Permissions: allPermissions } }) .update({ title: 'Admin' }, { $set: { permissions: allPermissions } })
.toPromise(), .toPromise(),
]); ]);
} }
...@@ -49,10 +49,8 @@ export const seedDB = async () => { ...@@ -49,10 +49,8 @@ export const seedDB = async () => {
password: 'admin', password: 'admin',
email: 'ali.arshad@vqode.com', email: 'ali.arshad@vqode.com',
profile: { profile: {
Role: Roles.findOne({ Title: 'Admin' })._id, // admin role id name: 'Admin User',
FirstName: 'Admin', role: Roles.findOne({ title: 'Admin' })._id, // admin role id
LastName: 'User',
Status: 'ACTIVE',
}, },
}); });
} }
......
...@@ -14,7 +14,7 @@ Meteor.startup(() => { ...@@ -14,7 +14,7 @@ Meteor.startup(() => {
Accounts.validateLoginAttempt((data): boolean => { Accounts.validateLoginAttempt((data): boolean => {
const user: Meteor.User = data.user; const user: Meteor.User = data.user;
return user && user.profile.Role return user && user.profile.role
&& UtilsService.hasPermissionOfUser(user, PERMISSIONS.CAN_LOGIN); && UtilsService.hasPermissionOfUser(user, PERMISSIONS.CAN_LOGIN);
}); });
......
...@@ -15,7 +15,7 @@ Meteor.methods({ ...@@ -15,7 +15,7 @@ Meteor.methods({
}, },
registerUser(user: any): string { registerUser(user: any): string {
const defaultRole = Roles.findOne({ Title: user.role }); const defaultRole = Roles.findOne({ title: user.role });
if (!Accounts.findUserByEmail(user.email)) { if (!Accounts.findUserByEmail(user.email)) {
const userObj = { const userObj = {
...@@ -23,8 +23,8 @@ Meteor.methods({ ...@@ -23,8 +23,8 @@ Meteor.methods({
password: user.password, password: user.password,
username: user.username, username: user.username,
profile: { profile: {
Name: user.name, name: user.name,
Role: defaultRole._id, role: defaultRole._id,
}, },
}; };
return Accounts.createUser(userObj); return Accounts.createUser(userObj);
...@@ -36,11 +36,12 @@ Meteor.methods({ ...@@ -36,11 +36,12 @@ Meteor.methods({
if (!UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_OWN_USER)) { if (!UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_OWN_USER)) {
throw new Meteor.Error(403, 'Forbidden.'); throw new Meteor.Error(403, 'Forbidden.');
} }
if (user._id) { if (user._id) {
const updateObj = { $set: { profile: user.profile } }; if (user.password) {
if (user.profile.Email) { Accounts.setPassword(user._id, user.password);
updateObj.$set['emails.0.address'] = user.profile.Email;
} }
const updateObj = { $set: { profile: user.profile } };
return Meteor.users.update(user._id, updateObj); return Meteor.users.update(user._id, updateObj);
} }
......
export interface Role { export interface Role {
_id?: string; _id?: string;
Title: string; title: string;
Permissions: string[]; permissions: string[];
Description: string; description: string;
} }
...@@ -22,7 +22,7 @@ publishComposite('usersList', (filters = {}) => { ...@@ -22,7 +22,7 @@ publishComposite('usersList', (filters = {}) => {
children: [ children: [
{ {
find(user): any { find(user): any {
return Roles.find({ _id: user.profile.Role }); return Roles.find({ _id: user.profile.role });
}, },
}, },
], ],
......
...@@ -8,30 +8,30 @@ export class UtilsService { ...@@ -8,30 +8,30 @@ export class UtilsService {
static getLoggedInUserPermissions(): string[] { static getLoggedInUserPermissions(): string[] {
const usr: Meteor.User = Meteor.user(); 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 { static hasPermission(permissions: string | string[]): boolean {
const usr: Meteor.User = Meteor.user(); const usr: Meteor.User = Meteor.user();
if (usr) { if (usr) {
const role = Roles.findOne(usr.profile.Role); const role = Roles.findOne(usr.profile.role);
if (typeof permissions === 'string') { 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; return false;
} }
static hasPermissionOfUser(user: Meteor.User, permission: string): boolean { 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> { 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