Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
angular-meteor
api
Commits
61c560b7
Commit
61c560b7
authored
Dec 16, 2019
by
GD-A-150752
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seeding-removed
parent
78911973
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
79 deletions
+64
-79
app.seeding.ts
server/app.seeding.ts
+0
-60
role.collection.ts
server/collections/role.collection.ts
+1
-1
main.ts
server/main.ts
+0
-6
roles.method.ts
server/methods/roles.method.ts
+2
-2
users.method.ts
server/methods/users.method.ts
+2
-2
migrations.ts
server/migrations.ts
+51
-0
roles.publication.ts
server/publications/roles.publication.ts
+2
-2
users.publication.ts
server/publications/users.publication.ts
+2
-2
utils.service.ts
server/services/utils.service.ts
+4
-4
No files found.
server/app.seeding.ts
deleted
100644 → 0
View file @
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.'
);
}
};
server/collections/role.collection.ts
View file @
61c560b7
...
@@ -2,4 +2,4 @@ import { MongoObservable } from 'meteor-rxjs';
...
@@ -2,4 +2,4 @@ import { MongoObservable } from 'meteor-rxjs';
import
{
RoleModel
}
from
'../models/role.model'
;
import
{
RoleModel
}
from
'../models/role.model'
;
// tslint:disable-next-line:variable-name
// tslint:disable-next-line:variable-name
export
const
Roles
=
new
MongoObservable
.
Collection
<
RoleModel
>
(
'roles'
);
export
const
rolesCollection
=
new
MongoObservable
.
Collection
<
RoleModel
>
(
'roles'
);
server/main.ts
View file @
61c560b7
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
seedDB
}
from
'./app.seeding'
;
import
{
PERMISSIONS
}
from
'./config'
;
import
{
PERMISSIONS
}
from
'./config'
;
import
{
UtilsService
}
from
'./services/utils.service'
;
import
{
UtilsService
}
from
'./services/utils.service'
;
Meteor
.
startup
(()
=>
{
Meteor
.
startup
(()
=>
{
const
seed
=
true
;
if
(
seed
)
{
seedDB
();
}
// @ts-ignore
// @ts-ignore
Migrations
.
migrateTo
(
'latest'
);
Migrations
.
migrateTo
(
'latest'
);
// Validate Login Attempt
// Validate Login Attempt
...
...
server/methods/roles.method.ts
View file @
61c560b7
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
first
}
from
'rxjs/operators'
;
import
{
first
}
from
'rxjs/operators'
;
import
{
Roles
}
from
'../collections/role.collection'
;
import
{
rolesCollection
}
from
'../collections/role.collection'
;
import
{
PERMISSIONS
}
from
'../config'
;
import
{
PERMISSIONS
}
from
'../config'
;
import
{
RoleModel
}
from
'../models/role.model'
;
import
{
RoleModel
}
from
'../models/role.model'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
...
@@ -9,7 +9,7 @@ Meteor.methods({
...
@@ -9,7 +9,7 @@ Meteor.methods({
async
saveRole
(
role
:
RoleModel
):
Promise
<
void
>
{
async
saveRole
(
role
:
RoleModel
):
Promise
<
void
>
{
try
{
try
{
if
(
role
.
_id
&&
UtilsService
.
hasPermission
(
PERMISSIONS
.
UPDATE_ROLE
))
{
if
(
role
.
_id
&&
UtilsService
.
hasPermission
(
PERMISSIONS
.
UPDATE_ROLE
))
{
await
Roles
.
update
(
role
.
_id
,
role
)
await
rolesCollection
.
update
(
role
.
_id
,
role
)
.
pipe
(
first
())
.
pipe
(
first
())
.
toPromise
();
.
toPromise
();
}
}
...
...
server/methods/users.method.ts
View file @
61c560b7
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Roles
}
from
'../collections/role.collection'
;
import
{
rolesCollection
}
from
'../collections/role.collection'
;
import
{
PERMISSIONS
}
from
'../config'
;
import
{
PERMISSIONS
}
from
'../config'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
QueryModel
}
from
'../models/query.model'
;
import
{
QueryModel
}
from
'../models/query.model'
;
...
@@ -16,7 +16,7 @@ Meteor.methods({
...
@@ -16,7 +16,7 @@ Meteor.methods({
},
},
registerUser
(
user
:
any
):
string
{
registerUser
(
user
:
any
):
string
{
const
defaultRole
=
Roles
.
findOne
({
title
:
user
.
role
});
const
defaultRole
=
rolesCollection
.
findOne
({
title
:
user
.
role
});
if
(
!
Accounts
.
findUserByEmail
(
user
.
email
))
{
if
(
!
Accounts
.
findUserByEmail
(
user
.
email
))
{
const
userObj
=
{
const
userObj
=
{
email
:
user
.
email
,
email
:
user
.
email
,
...
...
server/migrations.ts
View file @
61c560b7
import
{
settingsCollection
}
from
'./collections/setting.collections'
;
import
{
settingsCollection
}
from
'./collections/setting.collections'
;
import
{
PERMISSIONS
}
from
'./config'
;
import
{
rolesCollection
}
from
'./collections/role.collection'
;
import
{
Meteor
}
from
'meteor/meteor'
;
// @ts-ignore
// @ts-ignore
Migrations
.
add
({
Migrations
.
add
({
version
:
1
,
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'
,
name
:
'Adding Email Templates'
,
up
()
{
up
()
{
if
(
settingsCollection
.
find
({
REGISTER_HEADING
:
{
$exists
:
true
}
}).
fetch
().
length
===
0
)
{
if
(
settingsCollection
.
find
({
REGISTER_HEADING
:
{
$exists
:
true
}
}).
fetch
().
length
===
0
)
{
...
...
server/publications/roles.publication.ts
View file @
61c560b7
import
{
Meteor
}
from
'meteor/meteor'
;
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
({}));
server/publications/users.publication.ts
View file @
61c560b7
...
@@ -5,7 +5,7 @@ import { publishComposite } from 'meteor/reywood:publish-composite';
...
@@ -5,7 +5,7 @@ import { publishComposite } from 'meteor/reywood:publish-composite';
import
{
PERMISSIONS
}
from
'../config'
;
import
{
PERMISSIONS
}
from
'../config'
;
import
{
QueryModel
}
from
'../models/query.model'
;
import
{
QueryModel
}
from
'../models/query.model'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
Roles
}
from
'../collections/role.collection'
;
import
{
rolesCollection
}
from
'../collections/role.collection'
;
publishComposite
(
'usersList'
,
(
filters
=
{})
=>
{
publishComposite
(
'usersList'
,
(
filters
=
{})
=>
{
...
@@ -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
rolesCollection
.
find
({
_id
:
user
.
profile
.
role
});
},
},
},
},
],
],
...
...
server/services/utils.service.ts
View file @
61c560b7
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
import
AWS
=
require
(
'aws-sdk'
);
import
AWS
=
require
(
'aws-sdk'
);
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
Observable
,
Subject
}
from
'rxjs'
;
import
{
Observable
,
Subject
}
from
'rxjs'
;
import
{
Roles
}
from
'../collections/role.collection'
;
import
{
rolesCollection
}
from
'../collections/role.collection'
;
export
class
UtilsService
{
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
=
rolesCollection
.
findOne
(
usr
.
profile
.
role
);
return
role
.
permissions
;
return
role
.
permissions
;
}
}
...
@@ -16,7 +16,7 @@ export class UtilsService {
...
@@ -16,7 +16,7 @@ export class UtilsService {
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
=
rolesCollection
.
findOne
(
usr
.
profile
.
role
);
if
(
typeof
permissions
===
'string'
)
{
if
(
typeof
permissions
===
'string'
)
{
return
role
.
permissions
.
indexOf
(
permissions
)
!==
-
1
;
return
role
.
permissions
.
indexOf
(
permissions
)
!==
-
1
;
...
@@ -29,7 +29,7 @@ export class UtilsService {
...
@@ -29,7 +29,7 @@ export class UtilsService {
}
}
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
=
rolesCollection
.
findOne
(
user
.
profile
.
role
);
return
role
.
permissions
.
indexOf
(
permission
)
!==
-
1
;
return
role
.
permissions
.
indexOf
(
permission
)
!==
-
1
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment