Commit b9dd5952 by Tuukka Kivilahti

fixed moya inside glassfix, And added some permission tginys

1 parent 51e7e8e6
......@@ -3,6 +3,6 @@
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
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>
import {MenuGroup} from '../models/menu-group.model';
import {OldMoyaComponent} from '../../modules/old-moya/old-moya.component';
import {Permissions} from '../../shared/models/permissions.model';
/**
* 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 {
static ADMIN: MenuGroup[] = [
{
'name': 'shop',
'items': [
{ 'path': '/old/admin', 'name': 'products', 'params': {p: 'product/list.jsf'} }
{ 'path': '/old/admin', 'name': 'products', 'perm': _GP({'VIPLIST': 'ADMIN'}), 'params': {p: 'product/list.jsf'} }
]}
];
......@@ -20,8 +27,8 @@ export class MENU {
{
'name': 'users',
'items': [
{ 'path': '/old/info', 'name': 'listusers', 'params': {p: 'useradmin/list.jsf'} },
{ 'path': '/viplist/info', 'name': 'viplist'}
{ 'path': '/old/info', 'name': 'listusers', 'perm': _GP({'SITE': 'INFO'}), 'params': {p: 'useradmin/list.jsf'} },
{ 'path': '/viplist/info', 'perm': _GP({'VIPLIST': 'INFO'}), 'name': 'viplist'}
]}
];
......@@ -29,54 +36,53 @@ export class MENU {
{
'name': 'frontpage',
'items': [
{ 'path': '/index', 'name': 'frontpage' },
{ 'path': '/index', 'name': 'frontpage', 'perm': _GP({'SITE': 'USER'}) },
]},
{
'name': 'event',
'items': [
{ 'path': '/old/user', 'name': 'poll', 'params': {p: 'poll/index.jsf'} },
{ 'path': '/old/user', 'name': 'invite', 'params': {p: 'user/invite.jsf'} },
{ 'path': '/old/user', 'name': 'poll', 'perm': _GP({'POLL': 'USER'}), 'params': {p: 'poll/index.jsf'} },
{ 'path': '/old/user', 'name': 'invite', 'perm': _GP({'INVITE': 'USER'}), 'params': {p: 'user/invite.jsf'} },
]},
{
'name': 'shop',
'items': [
{ 'path': '/old/user', 'name': 'buytickets', 'params': {p: 'shop/createBill.jsf'} },
{ 'path': '/old/user', 'name': 'reserveplaces', 'params': {p: 'neomap/reserve.jsf'} },
{ 'path': '/old/user', 'name': 'changeplaces', 'params': {p: 'neomap/moveplaces.jsf'} },
{ 'path': '/old/user', 'name': 'foodorders', 'params': {p: 'foodwave/list.jsf'} },
{ 'path': '/old/user', 'name': 'ownorders', 'params': {p: 'bill/list.jsf'} },
{ 'path': '/old/user', 'name': 'accountevents', 'params': {p: 'user/accountEvents.jsf'} },
{ 'path': '/old/user', 'name': 'buytickets', 'perm': _GP({'SHOP': 'USER'}), 'params': {p: 'shop/createBill.jsf'} },
{ 'path': '/old/user', 'name': 'reserveplaces', 'perm': _GP({'MAP': 'USER'}), 'params': {p: 'neomap/reserve.jsf'} },
{ 'path': '/old/user', 'name': 'changeplaces', 'perm': _GP({'MAP': 'USER'}), 'params': {p: 'neomap/moveplaces.jsf'} },
{ 'path': '/old/user', 'name': 'foodorders', 'perm': _GP({'FOOD': 'USER'}), 'params': {p: 'foodwave/list.jsf'} },
{ 'path': '/old/user', 'name': 'ownorders', 'perm': _GP({'SHOP': 'USER', 'CREDIT': 'USER'}), 'params': {p: 'bill/list.jsf'} },
]},
{
'name': 'computerplaces',
'items': [
{ 'path': '/old/user', 'name': 'ownplaces', 'params': {p: 'place/myGroups.jsf'} },
{ 'path': '/old/user', 'name': 'placemap', 'params': {p: 'neomap/view.jsf'} },
{ 'path': '/old/user', 'name': 'ownplaces', 'perm': _GP({'MAP': 'USER'}), 'params': {p: 'place/myGroups.jsf'} },
{ 'path': '/old/user', 'name': 'placemap', 'perm': _GP({'MAP': 'USER'}), 'params': {p: 'neomap/view.jsf'} },
]},
{
'name': 'competitions',
'items': [
{ 'path': '/old/user', 'name': 'compos', 'params': {p: 'voting/compolist.jsf'} },
{ 'path': '/old/user', 'name': 'myentries', 'params': {p: 'voting/myEntries.jsf'} },
{ 'path': '/old/user', 'name': 'compos', 'perm': _GP({'COMPO': 'USER'}), 'params': {p: 'voting/compolist.jsf'} },
{ 'path': '/old/user', 'name': 'myentries', 'perm': _GP({'COMPO': 'USER'}), 'params': {p: 'voting/myEntries.jsf'} },
]},
{
'name': 'profile',
'items': [
{ 'path': '/old/user', 'name': 'myinformation', 'params': {p: 'user/edit.jsf'} },
{ 'path': '/old/user', 'name': 'requestrole', 'params': {p: 'orgrole/requestRole.jsf'} },
{ 'path': '/old/user', 'name': 'changepassword', 'params': {p: 'user/changePassword.jsf'} },
{ 'path': '/old/user', 'name': 'setgameids', 'params': {p: 'user/gameids.jsf'} },
{ 'path': '/old/user', 'name': 'myinformation', 'perm': _GP({'USER': 'USER'}), 'params': {p: 'user/edit.jsf'} },
{ 'path': '/old/user', 'name': 'requestrole', 'perm': _GP({'USER': 'USER'}), 'params': {p: 'orgrole/requestRole.jsf'} },
{ 'path': '/old/user', 'name': 'changepassword', 'perm': _GP({'USER': 'USER'}), 'params': {p: 'user/changePassword.jsf'} },
{ 'path': '/old/user', 'name': 'setgameids', 'perm': _GP({'USER': 'USER'}), 'params': {p: 'user/gameids.jsf'} },
]},
{
'name': 'tournaments',
'items': [
{ 'path': '/old/user', 'name': 'tournamentslist', 'params': {p: 'tournaments/index.jsf'} },
{ 'path': '/old/user', 'name': 'myparticipations', 'params': {p: 'tournaments/myparticipations.jsf'} },
{ 'path': '/old/user', 'name': 'tournamentslist', 'perm': _GP({'TOURNAMENT': 'USER'}), 'params': {p: 'tournaments/index.jsf'} },
{ 'path': '/old/user', 'name': 'myparticipations', 'perm': _GP({'TOURNAMENT': 'USER'}), 'params': {p: 'tournaments/myparticipations.jsf'} },
]},
{
'name': 'lecturesandcourses',
'items': [
{ 'path': '/old/user', 'name': 'participate', 'params': {p: 'lectures/viewLectures.jsf'} },
{ 'path': '/old/user', 'name': 'participate', 'perm': _GP({'LECTURE': 'USER'}), 'params': {p: 'lectures/viewLectures.jsf'} },
]},
];
......
import {Permissions} from '../../shared/models/permissions.model';
export interface MenuItem {
path: string;
name: string;
perm: (permissions: Permissions) => boolean;
params?: any;
}
......@@ -3,7 +3,7 @@ import {map} from 'rxjs/operators';
import {Component, OnInit, ViewChild, ElementRef, ApplicationRef, ChangeDetectorRef} from '@angular/core';
import {Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy} from '@angular/common';
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({
selector: 'moya-old',
......@@ -42,7 +42,7 @@ export class OldMoyaComponent implements OnInit {
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);
}
......@@ -50,7 +50,7 @@ export class OldMoyaComponent implements OnInit {
fixHeight(self) {
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';
this.changeDetectionRef.detectChanges();
}
......
......@@ -2,7 +2,7 @@ import {InMemoryCache} from 'apollo-cache-inmemory';
import {HttpLink} from 'apollo-angular-link-http';
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) {
......
/**
* Created by tuukka on 15/02/17.
* Created by tuukka on 22/09/18.
*/
import gql from 'graphql-tag';
class PermissionFields {
USER: boolean;
INFO: boolean;
ADMIN: boolean;
USER = false;
INFO = false;
ADMIN = false;
}
export class Permissions {
static referencePermission = new Permissions();
static fragments = gql`
fragment permissionPrimitives on Permission {
VIPLIST: {USER, INFO, ADMIN},
BILLING: {USER, INFO, ADMIN},
VIPLIST: PermissionFields = new PermissionFields();
BILLING: PermissionFields = new PermissionFields();
SITE: PermissionFields = new PermissionFields();
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;
};
}
}
import { Injectable } from '@angular/core';
import gql from 'graphql-tag';
import {Permission, Permissions} from "../models/permissions.model";
import {Apollo} from "apollo-angular";
import {map} from "rxjs/operators";
import {Q_VIPS_N_DATA} from "../../modules/viplist/viplist.service";
import {Observable} from "rxjs";
import { Permissions} from '../models/permissions.model';
import {Apollo} from 'apollo-angular';
import {Observable} from 'rxjs';
const __REFRESH_TIME_MINUTES = 5;
......@@ -14,9 +12,15 @@ export const Q_USER_PERMISSIONS = gql`
{
}
`;
class ApiPermissionType {
feature: string;
admin: boolean;
user: boolean;
info: boolean;
}
@Injectable({
providedIn: 'root'
})
......@@ -29,6 +33,14 @@ export class SessionServiceService {
}
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);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!