X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-frontend%2Fclient%2Fsrc%2Fapp%2Fshared%2Fservices%2Fuser.service.ts;fp=otf-frontend%2Fclient%2Fsrc%2Fapp%2Fshared%2Fservices%2Fuser.service.ts;h=0209ab5eb08c6d157defb85bdcfe54329039e1a4;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b diff --git a/otf-frontend/client/src/app/shared/services/user.service.ts b/otf-frontend/client/src/app/shared/services/user.service.ts new file mode 100644 index 0000000..0209ab5 --- /dev/null +++ b/otf-frontend/client/src/app/shared/services/user.service.ts @@ -0,0 +1,75 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { map } from 'rxjs/operators'; +import { ModelService } from './model.service'; +import { ParamsService } from './params.service'; +import { CookieService } from 'ngx-cookie-service'; +import { FeathersService } from './feathers.service'; +import { Ability } from '@casl/ability'; + + +@Injectable({ + providedIn: 'root' +}) +export class UserService extends ModelService { + + public ability: Ability; + + constructor(http: HttpClient, Params: ParamsService, cookie: CookieService, private c: CookieService, feathers: FeathersService){ + super('users', http, Params, cookie, feathers); + this.ability = new Ability(JSON.parse(localStorage.getItem('user_rules'))); + } + + getId(){ + return JSON.parse(this.cookie.get('currentUser'))._id; + } + + // addFavorite(ref: string, id: string){ + // return this.get(this.getId()).pipe(map( + // result => { + // if(!result['favorites']){ + // result['favorites'] = {}; + // } + // if(!result['favorites'][ref]){ + // result['favorites'][ref] = []; + // } + // result['favorites'][ref].push(id); + // result['favorites'][ref] = Array.from(new Set(result['favorites'][ref])); + // this.patch(result).subscribe(); + // } + // )); + // } + + // removeFavorite(ref: string, id: string){ + // return this.get(this.getId()).pipe(map( + // result => { + // result['favorites'][ref].splice( result['favorites'][ref].indexOf(id), 1 ); + // this.patch(result).subscribe(); + // } + // )); + // } + + enableUser(id: string, enabled: boolean){ + return this.patch({ + "_id" : id, + "enabled": enabled + }) + + } +} \ No newline at end of file