all files / app/services/ access.ts

52.38% Statements 11/21
0% Branches 0/8
33.33% Functions 1/3
50% Lines 9/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59            1× 1× 1×   1× 1× 1×     1×                                                       1×                           1×  
/* Copyright CloudLinux Zug GmbH 2010-2017 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */
 
import {Injectable} from '@angular/core';
import {Helper} from '../utils/helper';
import {AppState} from '../app.service';
 
export const OWNER_ADMIN: string = 'admin';
export const OWNER_USER: string = 'user';
export const OWNER_RESELLER: string = 'reseller';
 
@Injectable()
export class Access {
 
    public userType: string;
    public prohibitedLimits = {};
 
    constructor(public appState: AppState) {
        this.userType = this.appState.get('userType');
        this.prohibitedLimits[OWNER_RESELLER] = {
            usage: {
                cpu: { mysql: true },
                vmem: true,
                io: {mysql: true },
                inodes: true,
            },
            limits: {
                cpu: { mysql: true },
                vmem: true,
                io: {mysql: true },
                inodes: true,
            },
            faults: {
                vmem: true,
                io: {mysql: true },
                inodes: true,
            },
        };
    }
 
    public dropPermission(data, etalon) {
        if (this.userType === OWNER_ADMIN) return;
 
        if (this.userType === OWNER_RESELLER
            && this.prohibitedLimits.hasOwnProperty(this.userType)
        ) {
            Helper.removeBranchFromObject(
                etalon, this.prohibitedLimits[this.userType],
            );
            if (data.hasOwnProperty('mySqlGov')) {
                data['mySqlGov'] = 'error';
            }
        }
    }
}