mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-19 15:17:43 +01:00
Merge pull request #10340 from jwangyangls/modify-adminrole
Modify system admin role from has_admin_role to admin_role_in_auth and sysadmin_flag
This commit is contained in:
commit
3f53aa9476
@ -12,17 +12,23 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Define the session user
|
||||
export class SessionUser {
|
||||
export class SessionUserBase {
|
||||
user_id: number;
|
||||
username: string;
|
||||
email: string;
|
||||
realname: string;
|
||||
role_name?: string;
|
||||
role_id?: number;
|
||||
has_admin_role?: boolean;
|
||||
comment: string;
|
||||
oidc_user_meta?: OidcUserMeta;
|
||||
}
|
||||
export class SessionUser extends SessionUserBase {
|
||||
has_admin_role?: boolean;
|
||||
}
|
||||
export class SessionUserBackend extends SessionUserBase {
|
||||
admin_role_in_auth?: boolean;
|
||||
sysadmin_flag?: boolean;
|
||||
}
|
||||
export class OidcUserMeta {
|
||||
id: number;
|
||||
user_id: number;
|
||||
|
@ -15,11 +15,12 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import { Observable, throwError as observableThrowError } from "rxjs";
|
||||
import { SessionUser } from './session-user';
|
||||
import { SessionUser, SessionUserBackend } from './session-user';
|
||||
import { Member } from '../project/member/member';
|
||||
import { SignInCredential } from './sign-in-credential';
|
||||
import { enLang } from './shared.const';
|
||||
import { HTTP_FORM_OPTIONS, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS } from "../../lib/utils/utils";
|
||||
import { SessionViewmodelFactory } from './session.viewmodel.factory';
|
||||
import { HTTP_FORM_OPTIONS, HTTP_GET_OPTIONS, HTTP_JSON_OPTIONS, clone } from "../../lib/utils/utils";
|
||||
import { FlushAll } from "../../lib/utils/cache-util";
|
||||
|
||||
const signInUrl = '/c/login';
|
||||
@ -50,7 +51,7 @@ export class SessionService {
|
||||
"Content-Type": 'application/x-www-form-urlencoded'
|
||||
});*/
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
constructor(private http: HttpClient, public sessionViewmodel: SessionViewmodelFactory) { }
|
||||
|
||||
// Handle the related exceptions
|
||||
handleError(error: any): Observable<any> {
|
||||
@ -83,12 +84,11 @@ export class SessionService {
|
||||
*
|
||||
* @memberOf SessionService
|
||||
*/
|
||||
retrieveUser(): Observable<SessionUser> {
|
||||
retrieveUser(): Observable<SessionUserBackend> {
|
||||
return this.http.get(currentUserEndpoint, HTTP_GET_OPTIONS)
|
||||
.pipe(map(response => this.currentUser = response as SessionUser)
|
||||
.pipe(map((response: SessionUserBackend) => this.currentUser = this.sessionViewmodel.getCurrentUser(response) as SessionUser)
|
||||
, catchError(error => this.handleError(error)));
|
||||
}
|
||||
|
||||
/**
|
||||
* For getting info
|
||||
*/
|
||||
|
12
src/portal/src/app/shared/session.viewmodel.factory.spec.ts
Normal file
12
src/portal/src/app/shared/session.viewmodel.factory.spec.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SessionViewmodelFactory } from './session.viewmodel.factory';
|
||||
|
||||
describe('SessionViewmodelFactory', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: SessionViewmodelFactory = TestBed.get(SessionViewmodelFactory);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
25
src/portal/src/app/shared/session.viewmodel.factory.ts
Normal file
25
src/portal/src/app/shared/session.viewmodel.factory.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SessionUser, SessionUserBackend } from './session-user';
|
||||
import { clone } from "../../lib/utils/utils";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SessionViewmodelFactory {
|
||||
|
||||
constructor() { }
|
||||
// view model need
|
||||
getCurrentUser(currentUser: SessionUserBackend): SessionUser {
|
||||
return {
|
||||
user_id: currentUser.user_id,
|
||||
username: currentUser.username,
|
||||
email: currentUser.email,
|
||||
realname: currentUser.realname,
|
||||
role_name: currentUser.role_name,
|
||||
role_id: currentUser.role_id,
|
||||
comment: currentUser.comment,
|
||||
oidc_user_meta: currentUser.oidc_user_meta,
|
||||
has_admin_role: currentUser.admin_role_in_auth || currentUser.sysadmin_flag
|
||||
};
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
||||
if (user.user_id === 0 || this.isMySelf(user.user_id)) {
|
||||
return false;
|
||||
}
|
||||
if (user.has_admin_role) {
|
||||
if (user.sysadmin_flag) {
|
||||
usersRole.push(1);
|
||||
} else {
|
||||
usersRole.push(0);
|
||||
@ -136,7 +136,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
||||
if (!u) {
|
||||
return "{{MISS}}";
|
||||
}
|
||||
let key: string = u.has_admin_role ? "USER.IS_ADMIN" : "USER.IS_NOT_ADMIN";
|
||||
let key: string = u.sysadmin_flag ? "USER.IS_ADMIN" : "USER.IS_NOT_ADMIN";
|
||||
this.translate.get(key).subscribe((res: string) => this.adminColumn = res);
|
||||
return this.adminColumn;
|
||||
}
|
||||
@ -145,7 +145,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
||||
if (!u) {
|
||||
return "{{MISS}}";
|
||||
}
|
||||
let key: string = u.has_admin_role ? "USER.DISABLE_ADMIN_ACTION" : "USER.ENABLE_ADMIN_ACTION";
|
||||
let key: string = u.sysadmin_flag ? "USER.DISABLE_ADMIN_ACTION" : "USER.ENABLE_ADMIN_ACTION";
|
||||
this.translate.get(key).subscribe((res: string) => this.adminMenuText = res);
|
||||
return this.adminMenuText;
|
||||
}
|
||||
@ -196,7 +196,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
||||
let updatedUser: User = new User();
|
||||
updatedUser.user_id = this.selectedRow[i].user_id;
|
||||
|
||||
updatedUser.has_admin_role = true; // Set as admin
|
||||
updatedUser.sysadmin_flag = true; // Set as admin
|
||||
observableLists.push(this.userService.updateUserRole(updatedUser));
|
||||
}
|
||||
}
|
||||
@ -209,7 +209,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
||||
let updatedUser: User = new User();
|
||||
updatedUser.user_id = this.selectedRow[i].user_id;
|
||||
|
||||
updatedUser.has_admin_role = false; // Set as none admin
|
||||
updatedUser.sysadmin_flag = false; // Set as none admin
|
||||
observableLists.push(this.userService.updateUserRole(updatedUser));
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export class User {
|
||||
deleted?: boolean;
|
||||
role_name?: string;
|
||||
role_id?: number;
|
||||
has_admin_role?: boolean;
|
||||
sysadmin_flag?: boolean;
|
||||
reset_uuid?: string;
|
||||
creation_time?: string;
|
||||
update_time?: string;
|
||||
|
Loading…
Reference in New Issue
Block a user