Commit 61c560b7 by GD-A-150752

seeding-removed

parent 78911973
import { Meteor } from 'meteor/meteor';
import { Roles } from './collections/role.collection';
import { PERMISSIONS } from './config';
export const seedDB = async () => {
// tslint:disable-next-line:ban-ts-ignore
// @ts-ignore
const allPermissions = Object.values(PERMISSIONS);
try {
if (!Roles.find({})
.fetch().length || Roles.find({})
.fetch().length === 0) {
// Roles
await Promise.all([
Roles.insert({
title: 'Admin',
permissions: allPermissions,
description: '',
}).toPromise(),
Roles.insert({
title: 'User',
permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
description: '',
}).toPromise(),
Roles.insert({
title: 'Blocked',
permissions: [],
description: '',
}),
]);
} else {
// Update Roles Permissions
await Promise.all([
Roles
.update({ title: 'Admin' }, { $set: { permissions: allPermissions } })
.toPromise(),
]);
}
if (!Meteor.users.find({})
.fetch().length && Meteor.users.find({})
.fetch().length === 0) {
Accounts.createUser({
username: 'admin',
password: 'admin',
email: 'ali.arshad@vqode.com',
profile: {
name: 'Admin User',
role: Roles.findOne({ title: 'Admin' })._id, // admin role id
},
});
}
} catch (e) {
throw new Meteor.Error('Error while seeding database.');
}
};
......@@ -2,4 +2,4 @@ import { MongoObservable } from 'meteor-rxjs';
import { RoleModel } from '../models/role.model';
// tslint:disable-next-line:variable-name
export const Roles = new MongoObservable.Collection<RoleModel>('roles');
export const rolesCollection = new MongoObservable.Collection<RoleModel>('roles');
import { Meteor } from 'meteor/meteor';
import { seedDB } from './app.seeding';
import { PERMISSIONS } from './config';
import { UtilsService } from './services/utils.service';
Meteor.startup(() => {
const seed = true;
if (seed) {
seedDB();
}
// @ts-ignore
Migrations.migrateTo('latest');
// Validate Login Attempt
......
import { Meteor } from 'meteor/meteor';
import { first } from 'rxjs/operators';
import { Roles } from '../collections/role.collection';
import { rolesCollection } from '../collections/role.collection';
import { PERMISSIONS } from '../config';
import { RoleModel } from '../models/role.model';
import { UtilsService } from '../services/utils.service';
......@@ -9,7 +9,7 @@ Meteor.methods({
async saveRole(role: RoleModel): Promise<void> {
try {
if (role._id && UtilsService.hasPermission(PERMISSIONS.UPDATE_ROLE)) {
await Roles.update(role._id, role)
await rolesCollection.update(role._id, role)
.pipe(first())
.toPromise();
}
......
import { Meteor } from 'meteor/meteor';
import { Roles } from '../collections/role.collection';
import { rolesCollection } from '../collections/role.collection';
import { PERMISSIONS } from '../config';
import { UtilsService } from '../services/utils.service';
import { QueryModel } from '../models/query.model';
......@@ -16,7 +16,7 @@ Meteor.methods({
},
registerUser(user: any): string {
const defaultRole = Roles.findOne({ title: user.role });
const defaultRole = rolesCollection.findOne({ title: user.role });
if (!Accounts.findUserByEmail(user.email)) {
const userObj = {
email: user.email,
......
import { settingsCollection } from './collections/setting.collections';
import { PERMISSIONS } from './config';
import { rolesCollection } from './collections/role.collection';
import { Meteor } from 'meteor/meteor';
// @ts-ignore
Migrations.add({
version: 1,
name: 'Adding Roles',
up() {
const allPermissions = Object.values(PERMISSIONS);
if (!rolesCollection.find({}).fetch().length) {
rolesCollection.insert({
title: 'Admin',
permissions: allPermissions,
description: '',
});
rolesCollection.insert({
title: 'User',
permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
description: '',
});
rolesCollection.insert({
title: 'Blocked',
permissions: [],
description: '',
});
} else {
rolesCollection.update({ title: 'Admin' }, { $set: { permissions: allPermissions } });
}
},
});
// @ts-ignore
Migrations.add({
version: 2,
name: 'Adding Admin User',
up() {
if (!Meteor.users.find({}).fetch().length) {
Accounts.createUser({
username: 'admin',
password: 'admin',
email: 'ali.arshad@vqode.com',
profile: {
name: 'Admin User',
role: rolesCollection.findOne({ title: 'Admin' })._id,
},
});
}
},
});
// @ts-ignore
Migrations.add({
version: 3,
name: 'Adding Email Templates',
up() {
if (settingsCollection.find({ REGISTER_HEADING: { $exists: true } }).fetch().length === 0) {
......
import { Meteor } from 'meteor/meteor';
import { Roles } from '../collections/role.collection';
import { rolesCollection } from '../collections/role.collection';
Meteor.publish('roles', () => Roles.find({}));
Meteor.publish('roles', () => rolesCollection.find({}));
......@@ -5,7 +5,7 @@ import { publishComposite } from 'meteor/reywood:publish-composite';
import { PERMISSIONS } from '../config';
import { QueryModel } from '../models/query.model';
import { UtilsService } from '../services/utils.service';
import { Roles } from '../collections/role.collection';
import { rolesCollection } from '../collections/role.collection';
publishComposite('usersList', (filters = {}) => {
......@@ -22,7 +22,7 @@ publishComposite('usersList', (filters = {}) => {
children: [
{
find(user): any {
return Roles.find({ _id: user.profile.role });
return rolesCollection.find({ _id: user.profile.role });
},
},
],
......
......@@ -2,13 +2,13 @@
import AWS = require('aws-sdk');
import { Meteor } from 'meteor/meteor';
import { Observable, Subject } from 'rxjs';
import { Roles } from '../collections/role.collection';
import { rolesCollection } from '../collections/role.collection';
export class UtilsService {
static getLoggedInUserPermissions(): string[] {
const usr: Meteor.User = Meteor.user();
const role = Roles.findOne(usr.profile.role);
const role = rolesCollection.findOne(usr.profile.role);
return role.permissions;
}
......@@ -16,7 +16,7 @@ export class UtilsService {
static hasPermission(permissions: string | string[]): boolean {
const usr: Meteor.User = Meteor.user();
if (usr) {
const role = Roles.findOne(usr.profile.role);
const role = rolesCollection.findOne(usr.profile.role);
if (typeof permissions === 'string') {
return role.permissions.indexOf(permissions) !== -1;
......@@ -29,7 +29,7 @@ export class UtilsService {
}
static hasPermissionOfUser(user: Meteor.User, permission: string): boolean {
const role = Roles.findOne(user.profile.role);
const role = rolesCollection.findOne(user.profile.role);
return role.permissions.indexOf(permission) !== -1;
}
......
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