Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b9dd5952
authored
Sep 22, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed moya inside glassfix, And added some permission tginys
1 parent
51e7e8e6
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
51 deletions
code/moya-angular/WebContent/WEB-INF/pretty-config.xml
code/moya-angular/src/app/menu/defines/menu.ts
code/moya-angular/src/app/menu/models/menu-item.model.ts
code/moya-angular/src/app/modules/old-moya/old-moya.component.ts
code/moya-angular/src/app/shared/config/moya.config.ts
code/moya-angular/src/app/shared/models/permissions.model.ts
code/moya-angular/src/app/shared/services/session-service.service.ts
code/moya-angular/WebContent/WEB-INF/pretty-config.xml
View file @
b9dd595
...
@@ -3,6 +3,6 @@
...
@@ -3,6 +3,6 @@
xsi:schemaLocation=
"http://ocpsoft.org/schema/rewrite-config-prettyfaces
xsi:schemaLocation=
"http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd"
>
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd"
>
<rewrite
match=
"^(?!.*\.(js|css|jpg|gif|png|ico|html|svg)$).*$"
substitute=
"/index.html"
redirect=
"chain"
/>
<rewrite
match=
"^(?!.*\.(js|css|jpg|gif|png|ico|html|svg
|json
)$).*$"
substitute=
"/index.html"
redirect=
"chain"
/>
</pretty-config>
</pretty-config>
code/moya-angular/src/app/menu/defines/menu.ts
View file @
b9dd595
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
import
{
OldMoyaComponent
}
from
'../../modules/old-moya/old-moya.component'
;
import
{
OldMoyaComponent
}
from
'../../modules/old-moya/old-moya.component'
;
import
{
Permissions
}
from
'../../shared/models/permissions.model'
;
/**
/**
* Created by tuukka on 13/05/17.
* Created by tuukka on 13/05/17.
*/
*/
// We use GeneratePermissionFunction to make permission check functions
// This way if we can check permission names on software intialize, and will get exception if there is typo
const
_GP
=
Permissions
.
GeneratePermissionFunction
;
export
class
MENU
{
export
class
MENU
{
static
ADMIN
:
MenuGroup
[]
=
[
static
ADMIN
:
MenuGroup
[]
=
[
{
{
'name'
:
'shop'
,
'name'
:
'shop'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/admin'
,
'name'
:
'products'
,
'params'
:
{
p
:
'product/list.jsf'
}
}
{
'path'
:
'/old/admin'
,
'name'
:
'products'
,
'p
erm'
:
_GP
({
'VIPLIST'
:
'ADMIN'
}),
'p
arams'
:
{
p
:
'product/list.jsf'
}
}
]}
]}
];
];
...
@@ -20,8 +27,8 @@ export class MENU {
...
@@ -20,8 +27,8 @@ export class MENU {
{
{
'name'
:
'users'
,
'name'
:
'users'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/info'
,
'name'
:
'listusers'
,
'params'
:
{
p
:
'useradmin/list.jsf'
}
},
{
'path'
:
'/old/info'
,
'name'
:
'listusers'
,
'p
erm'
:
_GP
({
'SITE'
:
'INFO'
}),
'p
arams'
:
{
p
:
'useradmin/list.jsf'
}
},
{
'path'
:
'/viplist/info'
,
'name'
:
'viplist'
}
{
'path'
:
'/viplist/info'
,
'
perm'
:
_GP
({
'VIPLIST'
:
'INFO'
}),
'
name'
:
'viplist'
}
]}
]}
];
];
...
@@ -29,54 +36,53 @@ export class MENU {
...
@@ -29,54 +36,53 @@ export class MENU {
{
{
'name'
:
'frontpage'
,
'name'
:
'frontpage'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/index'
,
'name'
:
'frontpage'
},
{
'path'
:
'/index'
,
'name'
:
'frontpage'
,
'perm'
:
_GP
({
'SITE'
:
'USER'
})
},
]},
]},
{
{
'name'
:
'event'
,
'name'
:
'event'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'poll'
,
'params'
:
{
p
:
'poll/index.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'poll'
,
'p
erm'
:
_GP
({
'POLL'
:
'USER'
}),
'p
arams'
:
{
p
:
'poll/index.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'invite'
,
'params'
:
{
p
:
'user/invite.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'invite'
,
'p
erm'
:
_GP
({
'INVITE'
:
'USER'
}),
'p
arams'
:
{
p
:
'user/invite.jsf'
}
},
]},
]},
{
{
'name'
:
'shop'
,
'name'
:
'shop'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'buytickets'
,
'params'
:
{
p
:
'shop/createBill.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'buytickets'
,
'perm'
:
_GP
({
'SHOP'
:
'USER'
}),
'params'
:
{
p
:
'shop/createBill.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'reserveplaces'
,
'params'
:
{
p
:
'neomap/reserve.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'reserveplaces'
,
'perm'
:
_GP
({
'MAP'
:
'USER'
}),
'params'
:
{
p
:
'neomap/reserve.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'changeplaces'
,
'params'
:
{
p
:
'neomap/moveplaces.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'changeplaces'
,
'perm'
:
_GP
({
'MAP'
:
'USER'
}),
'params'
:
{
p
:
'neomap/moveplaces.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'foodorders'
,
'params'
:
{
p
:
'foodwave/list.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'foodorders'
,
'perm'
:
_GP
({
'FOOD'
:
'USER'
}),
'params'
:
{
p
:
'foodwave/list.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'ownorders'
,
'params'
:
{
p
:
'bill/list.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'ownorders'
,
'perm'
:
_GP
({
'SHOP'
:
'USER'
,
'CREDIT'
:
'USER'
}),
'params'
:
{
p
:
'bill/list.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'accountevents'
,
'params'
:
{
p
:
'user/accountEvents.jsf'
}
},
]},
]},
{
{
'name'
:
'computerplaces'
,
'name'
:
'computerplaces'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'ownplaces'
,
'params'
:
{
p
:
'place/myGroups.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'ownplaces'
,
'p
erm'
:
_GP
({
'MAP'
:
'USER'
}),
'p
arams'
:
{
p
:
'place/myGroups.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'placemap'
,
'params'
:
{
p
:
'neomap/view.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'placemap'
,
'p
erm'
:
_GP
({
'MAP'
:
'USER'
}),
'p
arams'
:
{
p
:
'neomap/view.jsf'
}
},
]},
]},
{
{
'name'
:
'competitions'
,
'name'
:
'competitions'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'compos'
,
'params'
:
{
p
:
'voting/compolist.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'compos'
,
'p
erm'
:
_GP
({
'COMPO'
:
'USER'
}),
'p
arams'
:
{
p
:
'voting/compolist.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'myentries'
,
'params'
:
{
p
:
'voting/myEntries.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'myentries'
,
'p
erm'
:
_GP
({
'COMPO'
:
'USER'
}),
'p
arams'
:
{
p
:
'voting/myEntries.jsf'
}
},
]},
]},
{
{
'name'
:
'profile'
,
'name'
:
'profile'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'myinformation'
,
'params'
:
{
p
:
'user/edit.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'myinformation'
,
'p
erm'
:
_GP
({
'USER'
:
'USER'
}),
'p
arams'
:
{
p
:
'user/edit.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'requestrole'
,
'params'
:
{
p
:
'orgrole/requestRole.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'requestrole'
,
'p
erm'
:
_GP
({
'USER'
:
'USER'
}),
'p
arams'
:
{
p
:
'orgrole/requestRole.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'changepassword'
,
'params'
:
{
p
:
'user/changePassword.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'changepassword'
,
'p
erm'
:
_GP
({
'USER'
:
'USER'
}),
'p
arams'
:
{
p
:
'user/changePassword.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'setgameids'
,
'params'
:
{
p
:
'user/gameids.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'setgameids'
,
'p
erm'
:
_GP
({
'USER'
:
'USER'
}),
'p
arams'
:
{
p
:
'user/gameids.jsf'
}
},
]},
]},
{
{
'name'
:
'tournaments'
,
'name'
:
'tournaments'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'tournamentslist'
,
'params'
:
{
p
:
'tournaments/index.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'tournamentslist'
,
'p
erm'
:
_GP
({
'TOURNAMENT'
:
'USER'
}),
'p
arams'
:
{
p
:
'tournaments/index.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'myparticipations'
,
'params'
:
{
p
:
'tournaments/myparticipations.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'myparticipations'
,
'p
erm'
:
_GP
({
'TOURNAMENT'
:
'USER'
}),
'p
arams'
:
{
p
:
'tournaments/myparticipations.jsf'
}
},
]},
]},
{
{
'name'
:
'lecturesandcourses'
,
'name'
:
'lecturesandcourses'
,
'items'
:
[
'items'
:
[
{
'path'
:
'/old/user'
,
'name'
:
'participate'
,
'params'
:
{
p
:
'lectures/viewLectures.jsf'
}
},
{
'path'
:
'/old/user'
,
'name'
:
'participate'
,
'p
erm'
:
_GP
({
'LECTURE'
:
'USER'
}),
'p
arams'
:
{
p
:
'lectures/viewLectures.jsf'
}
},
]},
]},
];
];
...
...
code/moya-angular/src/app/menu/models/menu-item.model.ts
View file @
b9dd595
import
{
Permissions
}
from
'../../shared/models/permissions.model'
;
export
interface
MenuItem
{
export
interface
MenuItem
{
path
:
string
;
path
:
string
;
name
:
string
;
name
:
string
;
perm
:
(
permissions
:
Permissions
)
=>
boolean
;
params
?:
any
;
params
?:
any
;
}
}
code/moya-angular/src/app/modules/old-moya/old-moya.component.ts
View file @
b9dd595
...
@@ -3,7 +3,7 @@ import {map} from 'rxjs/operators';
...
@@ -3,7 +3,7 @@ import {map} from 'rxjs/operators';
import
{
Component
,
OnInit
,
ViewChild
,
ElementRef
,
ApplicationRef
,
ChangeDetectorRef
}
from
'@angular/core'
;
import
{
Component
,
OnInit
,
ViewChild
,
ElementRef
,
ApplicationRef
,
ChangeDetectorRef
}
from
'@angular/core'
;
import
{
Location
,
LocationStrategy
,
HashLocationStrategy
,
PathLocationStrategy
}
from
'@angular/common'
;
import
{
Location
,
LocationStrategy
,
HashLocationStrategy
,
PathLocationStrategy
}
from
'@angular/common'
;
import
{
NavigationExtras
,
ActivatedRoute
,
Router
}
from
'@angular/router'
;
import
{
NavigationExtras
,
ActivatedRoute
,
Router
}
from
'@angular/router'
;
import
{
angularCoreEnv
}
from
"@angular/core/src/render3/jit/environment"
;
import
{
angularCoreEnv
}
from
'@angular/core/src/render3/jit/environment'
;
@
Component
({
@
Component
({
selector
:
'moya-old'
,
selector
:
'moya-old'
,
...
@@ -42,7 +42,7 @@ export class OldMoyaComponent implements OnInit {
...
@@ -42,7 +42,7 @@ export class OldMoyaComponent implements OnInit {
this
.
location
.
replaceState
(
this
.
location
.
path
(
false
).
split
(
'?'
,
1
)[
0
]
+
'?p='
+
tmpFrameUrl
[
1
].
replace
(
'?'
,
'::'
)
);
this
.
location
.
replaceState
(
this
.
location
.
path
(
false
).
split
(
'?'
,
1
)[
0
]
+
'?p='
+
tmpFrameUrl
[
1
].
replace
(
'?'
,
'::'
)
);
}
}
this
.
iframe
.
nativeElement
.
contentWindow
.
onscroll
=
(()
=>
{
this
.
fixHeight
(
this
)});
this
.
iframe
.
nativeElement
.
contentWindow
.
onscroll
=
(()
=>
{
this
.
fixHeight
(
this
)
;
});
this
.
fixHeight
(
this
);
this
.
fixHeight
(
this
);
}
}
...
@@ -50,7 +50,7 @@ export class OldMoyaComponent implements OnInit {
...
@@ -50,7 +50,7 @@ export class OldMoyaComponent implements OnInit {
fixHeight
(
self
)
{
fixHeight
(
self
)
{
console
.
log
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
);
console
.
log
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
);
if
(
self
.
height
!
=
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
+
50
)
+
'px'
)
{
if
(
self
.
height
!=
=
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
+
50
)
+
'px'
)
{
self
.
height
=
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
+
50
)
+
'px'
;
self
.
height
=
(
self
.
iframe
.
nativeElement
.
contentWindow
.
document
.
body
.
scrollHeight
+
50
)
+
'px'
;
this
.
changeDetectionRef
.
detectChanges
();
this
.
changeDetectionRef
.
detectChanges
();
}
}
...
...
code/moya-angular/src/app/shared/config/moya.config.ts
View file @
b9dd595
...
@@ -2,7 +2,7 @@ import {InMemoryCache} from 'apollo-cache-inmemory';
...
@@ -2,7 +2,7 @@ import {InMemoryCache} from 'apollo-cache-inmemory';
import
{
HttpLink
}
from
'apollo-angular-link-http'
;
import
{
HttpLink
}
from
'apollo-angular-link-http'
;
export
const
MOYA_BASE_URL
=
'/MoyaWeb/'
;
export
const
MOYA_BASE_URL
=
'/MoyaWeb/'
;
export
const
MOYA_REST_URL
=
MOYA_BASE_URL
+
'rest
/
'
;
export
const
MOYA_REST_URL
=
MOYA_BASE_URL
+
'rest'
;
export
function
createApollo
(
httpLink
:
HttpLink
)
{
export
function
createApollo
(
httpLink
:
HttpLink
)
{
...
...
code/moya-angular/src/app/shared/models/permissions.model.ts
View file @
b9dd595
/**
/**
* Created by tuukka on
15/02/17
.
* Created by tuukka on
22/09/18
.
*/
*/
import
gql
from
'graphql-tag'
;
class
PermissionFields
{
class
PermissionFields
{
USER
:
boolean
;
USER
=
false
;
INFO
:
boolean
;
INFO
=
false
;
ADMIN
:
boolean
;
ADMIN
=
false
;
}
}
export
class
Permissions
{
export
class
Permissions
{
static
referencePermission
=
new
Permissions
();
static
fragments
=
gql
`
VIPLIST
:
PermissionFields
=
new
PermissionFields
();
fragment permissionPrimitives on Permission {
BILLING
:
PermissionFields
=
new
PermissionFields
();
VIPLIST: {USER, INFO, ADMIN},
SITE
:
PermissionFields
=
new
PermissionFields
();
BILLING: {USER, INFO, ADMIN},
SHOP
:
PermissionFields
=
new
PermissionFields
();
POLL
:
PermissionFields
=
new
PermissionFields
();
INVITE
:
PermissionFields
=
new
PermissionFields
();
MAP
:
PermissionFields
=
new
PermissionFields
();
COMPO
:
PermissionFields
=
new
PermissionFields
();
FOOD
:
PermissionFields
=
new
PermissionFields
();
USER
:
PermissionFields
=
new
PermissionFields
();
TOURNAMENT
:
PermissionFields
=
new
PermissionFields
();
CREDIT
:
PermissionFields
=
new
PermissionFields
();
LECTURE
:
PermissionFields
=
new
PermissionFields
();
constructor
()
{
}
}
`
;
VIPLIST
:
PermissionFields
;
BILLING
:
PermissionFields
;
constructor
()
{
}
/**
*
* Returns function, which will check user permissions against desired roles.
*
* Returned function can be used as a permission checked.
*
*
* @param requiredPermissions Permissions which are allowed. Example: {VIPLIST: 'ADMIN', BILLING: 'INFO'}
* @constructor
*/
static
GeneratePermissionFunction
(
allowedPermissions
:
any
):
((
permissions
:
Permissions
)
=>
boolean
)
{
// no defines, always true
if
(
!
allowedPermissions
)
{
return
function
(
permissions
:
Permissions
):
boolean
{
return
true
;
};
}
// Check if all permissions exists
// Think this as a runtime typecheck
for
(
const
target
in
allowedPermissions
)
{
if
(
!
allowedPermissions
.
hasOwnProperty
(
target
))
{
continue
;
}
if
(
!
(
target
in
Permissions
.
referencePermission
))
{
throw
Error
(
'Invalid permission key '
+
target
);
}
switch
(
allowedPermissions
[
target
])
{
default
:
throw
Error
(
'Invalid permission role '
+
allowedPermissions
[
target
]);
case
'ADMIN'
:
case
'INFO'
:
case
'USER'
:
}
}
return
function
(
permissions
:
Permissions
):
boolean
{
// Go trought allowed permissions. If permissions contains allowed permission, return true.
for
(
const
target
in
allowedPermissions
)
{
if
(
permissions
[
target
][
allowedPermissions
[
target
]])
{
return
true
;
}
}
// no permission found, return false
return
false
;
};
}
}
}
code/moya-angular/src/app/shared/services/session-service.service.ts
View file @
b9dd595
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
gql
from
'graphql-tag'
;
import
gql
from
'graphql-tag'
;
import
{
Permission
,
Permissions
}
from
"../models/permissions.model"
;
import
{
Permissions
}
from
'../models/permissions.model'
;
import
{
Apollo
}
from
"apollo-angular"
;
import
{
Apollo
}
from
'apollo-angular'
;
import
{
map
}
from
"rxjs/operators"
;
import
{
Observable
}
from
'rxjs'
;
import
{
Q_VIPS_N_DATA
}
from
"../../modules/viplist/viplist.service"
;
import
{
Observable
}
from
"rxjs"
;
const
__REFRESH_TIME_MINUTES
=
5
;
const
__REFRESH_TIME_MINUTES
=
5
;
...
@@ -14,9 +12,15 @@ export const Q_USER_PERMISSIONS = gql`
...
@@ -14,9 +12,15 @@ export const Q_USER_PERMISSIONS = gql`
{
{
}
}
`
;
`
;
class
ApiPermissionType
{
feature
:
string
;
admin
:
boolean
;
user
:
boolean
;
info
:
boolean
;
}
@
Injectable
({
@
Injectable
({
providedIn
:
'root'
providedIn
:
'root'
})
})
...
@@ -29,6 +33,14 @@ export class SessionServiceService {
...
@@ -29,6 +33,14 @@ export class SessionServiceService {
}
}
constructor
(
private
apollo
:
Apollo
)
{
constructor
(
private
apollo
:
Apollo
)
{
this
.
permissionsObservable
=
this
.
apollo
.
watchQuery
<
Permissions
>
({
query
:
Q_USER_PERMISSIONS
,
pollInterval
:
__REFRESH_TIME_MINUTES
*
60000
});
// rewrite permissions from API -format to moya-angular -format
//
// From:
// [{feature: 'VIPLIST', user:true, admin: false, info:false}, {feature: 'USERLIST', user:true, admin: false, info:false}]
// To:
// {VIPLIST: {USER: true, ADMIN: false, INFO: false}, USERLIST: {USER: true, ADMIN: false, INFO: false}}
this
.
permissionsObservable
=
this
.
apollo
.
watchQuery
<
Array
<
ApiPermissionType
>>
({
query
:
Q_USER_PERMISSIONS
,
pollInterval
:
__REFRESH_TIME_MINUTES
*
60000
}).
valueChanges
.
map
((
perms
)
=>
perms
.
data
.
reduce
((
permObject
,
perm
)
=>
(
permObject
[
perm
.
feature
]
=
{
'ADMIN'
:
perm
.
admin
,
'USER'
:
perm
.
user
,
'INFO'
:
perm
.
info
}),
{})
as
Permissions
);
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment