1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Component, OnInit, Inject } from '@angular/core';
\r
18 import { MatDialogRef, MAT_DIALOG_DATA, MatSnackBar, MatDialog } from '@angular/material';
\r
19 import { GroupService } from 'app/shared/services/group.service';
\r
20 import { CookieService } from 'ngx-cookie-service';
\r
21 import { UserService } from 'app/shared/services/user.service';
\r
22 import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';
\r
23 import { AlertModalComponent } from 'app/shared/modules/alert-modal/alert-modal.component';
\r
27 selector: 'app-create-group-modal',
\r
28 templateUrl: './create-group-modal.component.pug',
\r
29 styleUrls: ['./create-group-modal.component.scss']
\r
31 export class CreateGroupModalComponent implements OnInit {
\r
33 constructor(public dialogRef: MatDialogRef<CreateGroupModalComponent>, @Inject(MAT_DIALOG_DATA) public input_data, private userService: UserService, private groupService: GroupService, private cookieService: CookieService, private snack: MatSnackBar, private modal: MatDialog) { }
\r
43 this.newGroup.groupName = '';
\r
44 this.newGroup.parentGroupId = null;
\r
45 this.user._id = this.userService.getId();
\r
46 this.newGroup.ownerId = this.user["_id"];
\r
47 //filter list of groups by the Admin permssion from the user
\r
48 //Also add group onto active dropdown list when this dialog is closed
\r
49 this.groupService.find({
\r
52 }).subscribe((list) => {
\r
53 //console.log(list);
\r
55 //console.log(this.user._id + " " + list[i]);
\r
56 if(this.checkIsAdmin(list[i], this.user._id)){
\r
57 this.groups.push(list[i]);
\r
65 checkIsAdmin(group, userId){
\r
67 let memberIndex = group.members.findIndex(function(member){return member.userId.toString() == userId.toString()});
\r
68 if(memberIndex >= 0){
\r
69 if(group.members[memberIndex].roles.includes("admin")){
\r
79 this.dialogRef.close(null);
\r
84 //console.log(this.newGroup);
\r
85 if(this.newGroup.parentGroupId == "None"){
\r
86 this.newGroup.parentGroupId = null;
\r
89 this.newGroup.roles = [{
\r
91 permissions: ["management", "write", "delete", "read", "execute"]
\r
95 permissions: ["read"]
\r
98 roleName: "developer",
\r
99 permissions: ["write", "delete", "read", "execute"]
\r
101 this.newGroup.members = [{
\r
102 userId: this.user._id,
\r
105 this.groupService.create(this.newGroup).subscribe(res => {
\r
107 let snackMessage = 'The group ' + this.newGroup.groupName + " has been created!";
\r
108 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
111 message: snackMessage
\r
115 this.dialogRef.close(res)
\r
120 this.modal.open(AlertModalComponent, {
\r