From bcd9f81eff05ffd930c5d8175fb907d4d371432a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Oct 2017 17:31:11 +0200 Subject: [PATCH] Add channels to upload form --- client/src/app/app.component.ts | 2 +- client/src/app/core/auth/auth-user.model.ts | 10 +--- client/src/app/core/auth/auth.service.ts | 48 ++++++++++++++----- .../app/shared/forms/form-validators/video.ts | 7 +++ client/src/app/shared/users/user.service.ts | 7 --- .../+video-edit/video-add.component.html | 12 +++++ .../videos/+video-edit/video-add.component.ts | 13 ++++- .../videos/video-list/video-list.component.ts | 10 +--- server/tests/api/friends-advanced.ts | 4 +- 9 files changed, 72 insertions(+), 41 deletions(-) diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 7d890e72a..984470d69 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -37,7 +37,7 @@ export class AppComponent implements OnInit { if (this.authService.isLoggedIn()) { // The service will automatically redirect to the login page if the token is not valid anymore - this.userService.checkTokenValidity() + this.authService.refreshUserInformation() } // Load custom data from server diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 4155aea19..81bff99a0 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -1,6 +1,6 @@ // Do not use the barrel (dependency loop) import { UserRole } from '../../../../../shared/models/users/user-role.type' -import { User } from '../../shared/users/user.model' +import { User, UserConstructorHash } from '../../shared/users/user.model' export type TokenOptions = { accessToken: string @@ -100,13 +100,7 @@ export class AuthUser extends User { Tokens.flush() } - constructor (userHash: { - id: number, - username: string, - role: UserRole, - email: string, - displayNSFW: boolean - }, hashTokens: TokenOptions) { + constructor (userHash: UserConstructorHash, hashTokens: TokenOptions) { super(userHash) this.tokens = new Tokens(hashTokens) } diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 4a8814c4e..9ac9ba7bb 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,11 +11,17 @@ import { NotificationsService } from 'angular2-notifications' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' -import { OAuthClientLocal, UserRole, UserRefreshToken } from '../../../../../shared' +import { + OAuthClientLocal, + UserRole, + UserRefreshToken, + VideoChannel, + User as UserServerModel +} from '../../../../../shared' // Do not use the barrel (dependency loop) import { RestExtractor } from '../../shared/rest' import { UserLogin } from '../../../../../shared/models/users/user-login.model' -import { User } from '../../shared/users/user.model' +import { User, UserConstructorHash } from '../../shared/users/user.model' interface UserLoginWithUsername extends UserLogin { access_token: string @@ -33,6 +39,12 @@ interface UserLoginWithUserInformation extends UserLogin { role: UserRole displayNSFW: boolean email: string + videoQuota: number + author: { + id: number + uuid: string + } + videoChannels: VideoChannel[] } @Injectable() @@ -197,6 +209,8 @@ export class AuthService { res => { this.user.displayNSFW = res.displayNSFW this.user.role = res.role + this.user.videoChannels = res.videoChannels + this.user.author = res.author this.user.save() } @@ -207,13 +221,16 @@ export class AuthService { // User is not loaded yet, set manually auth header const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`) - return this.http.get(AuthService.BASE_USER_INFORMATION_URL, { headers }) + return this.http.get(AuthService.BASE_USER_INFORMATION_URL, { headers }) .map(res => { const newProperties = { - id: res.id as number, - role: res.role as UserRole, - displayNSFW: res.displayNSFW as boolean, - email: res.email as string + id: res.id, + role: res.role, + displayNSFW: res.displayNSFW, + email: res.email, + videoQuota: res.videoQuota, + author: res.author, + videoChannels: res.videoChannels } return Object.assign(obj, newProperties) @@ -222,18 +239,23 @@ export class AuthService { } private handleLogin (obj: UserLoginWithUserInformation) { - const id = obj.id - const username = obj.username - const role = obj.role - const email = obj.email - const displayNSFW = obj.displayNSFW + const hashUser: UserConstructorHash = { + id: obj.id, + username: obj.username, + role: obj.role, + email: obj.email, + displayNSFW: obj.displayNSFW, + videoQuota: obj.videoQuota, + videoChannels: obj.videoChannels, + author: obj.author + } const hashTokens = { accessToken: obj.access_token, tokenType: obj.token_type, refreshToken: obj.refresh_token } - this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens) + this.user = new AuthUser(hashUser, hashTokens) this.user.save() this.setStatus(AuthStatus.LoggedIn) diff --git a/client/src/app/shared/forms/form-validators/video.ts b/client/src/app/shared/forms/form-validators/video.ts index 32b1f1c2e..213ab15db 100644 --- a/client/src/app/shared/forms/form-validators/video.ts +++ b/client/src/app/shared/forms/form-validators/video.ts @@ -28,6 +28,13 @@ export const VIDEO_LANGUAGE = { MESSAGES: {} } +export const VIDEO_CHANNEL = { + VALIDATORS: [ Validators.required ], + MESSAGES: { + 'required': 'Video channel is required.' + } +} + export const VIDEO_DESCRIPTION = { VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ], MESSAGES: { diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 5c089d221..6d1017fc9 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -15,13 +15,6 @@ export class UserService { private restExtractor: RestExtractor ) {} - checkTokenValidity () { - const url = UserService.BASE_USERS_URL + 'me' - - // AuthHttp will redirect us to the login page if the token is not valid anymore - this.authHttp.get(url).subscribe() - } - changePassword (newPassword: string) { const url = UserService.BASE_USERS_URL + 'me' const body: UserUpdateMe = { diff --git a/client/src/app/videos/+video-edit/video-add.component.html b/client/src/app/videos/+video-edit/video-add.component.html index 698152ff9..7946c0879 100644 --- a/client/src/app/videos/+video-edit/video-add.component.html +++ b/client/src/app/videos/+video-edit/video-add.component.html @@ -25,6 +25,18 @@ > +
+ + + +
+ {{ formErrors.channelId }} +
+
+