Add channels to upload form
This commit is contained in:
parent
d412e80e5f
commit
bcd9f81eff
|
@ -37,7 +37,7 @@ export class AppComponent implements OnInit {
|
||||||
|
|
||||||
if (this.authService.isLoggedIn()) {
|
if (this.authService.isLoggedIn()) {
|
||||||
// The service will automatically redirect to the login page if the token is not valid anymore
|
// 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
|
// Load custom data from server
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Do not use the barrel (dependency loop)
|
// Do not use the barrel (dependency loop)
|
||||||
import { UserRole } from '../../../../../shared/models/users/user-role.type'
|
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 = {
|
export type TokenOptions = {
|
||||||
accessToken: string
|
accessToken: string
|
||||||
|
@ -100,13 +100,7 @@ export class AuthUser extends User {
|
||||||
Tokens.flush()
|
Tokens.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (userHash: {
|
constructor (userHash: UserConstructorHash, hashTokens: TokenOptions) {
|
||||||
id: number,
|
|
||||||
username: string,
|
|
||||||
role: UserRole,
|
|
||||||
email: string,
|
|
||||||
displayNSFW: boolean
|
|
||||||
}, hashTokens: TokenOptions) {
|
|
||||||
super(userHash)
|
super(userHash)
|
||||||
this.tokens = new Tokens(hashTokens)
|
this.tokens = new Tokens(hashTokens)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,17 @@ import { NotificationsService } from 'angular2-notifications'
|
||||||
|
|
||||||
import { AuthStatus } from './auth-status.model'
|
import { AuthStatus } from './auth-status.model'
|
||||||
import { AuthUser } from './auth-user.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)
|
// Do not use the barrel (dependency loop)
|
||||||
import { RestExtractor } from '../../shared/rest'
|
import { RestExtractor } from '../../shared/rest'
|
||||||
import { UserLogin } from '../../../../../shared/models/users/user-login.model'
|
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 {
|
interface UserLoginWithUsername extends UserLogin {
|
||||||
access_token: string
|
access_token: string
|
||||||
|
@ -33,6 +39,12 @@ interface UserLoginWithUserInformation extends UserLogin {
|
||||||
role: UserRole
|
role: UserRole
|
||||||
displayNSFW: boolean
|
displayNSFW: boolean
|
||||||
email: string
|
email: string
|
||||||
|
videoQuota: number
|
||||||
|
author: {
|
||||||
|
id: number
|
||||||
|
uuid: string
|
||||||
|
}
|
||||||
|
videoChannels: VideoChannel[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -197,6 +209,8 @@ export class AuthService {
|
||||||
res => {
|
res => {
|
||||||
this.user.displayNSFW = res.displayNSFW
|
this.user.displayNSFW = res.displayNSFW
|
||||||
this.user.role = res.role
|
this.user.role = res.role
|
||||||
|
this.user.videoChannels = res.videoChannels
|
||||||
|
this.user.author = res.author
|
||||||
|
|
||||||
this.user.save()
|
this.user.save()
|
||||||
}
|
}
|
||||||
|
@ -207,13 +221,16 @@ export class AuthService {
|
||||||
// User is not loaded yet, set manually auth header
|
// User is not loaded yet, set manually auth header
|
||||||
const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`)
|
const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`)
|
||||||
|
|
||||||
return this.http.get<User>(AuthService.BASE_USER_INFORMATION_URL, { headers })
|
return this.http.get<UserServerModel>(AuthService.BASE_USER_INFORMATION_URL, { headers })
|
||||||
.map(res => {
|
.map(res => {
|
||||||
const newProperties = {
|
const newProperties = {
|
||||||
id: res.id as number,
|
id: res.id,
|
||||||
role: res.role as UserRole,
|
role: res.role,
|
||||||
displayNSFW: res.displayNSFW as boolean,
|
displayNSFW: res.displayNSFW,
|
||||||
email: res.email as string
|
email: res.email,
|
||||||
|
videoQuota: res.videoQuota,
|
||||||
|
author: res.author,
|
||||||
|
videoChannels: res.videoChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.assign(obj, newProperties)
|
return Object.assign(obj, newProperties)
|
||||||
|
@ -222,18 +239,23 @@ export class AuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleLogin (obj: UserLoginWithUserInformation) {
|
private handleLogin (obj: UserLoginWithUserInformation) {
|
||||||
const id = obj.id
|
const hashUser: UserConstructorHash = {
|
||||||
const username = obj.username
|
id: obj.id,
|
||||||
const role = obj.role
|
username: obj.username,
|
||||||
const email = obj.email
|
role: obj.role,
|
||||||
const displayNSFW = obj.displayNSFW
|
email: obj.email,
|
||||||
|
displayNSFW: obj.displayNSFW,
|
||||||
|
videoQuota: obj.videoQuota,
|
||||||
|
videoChannels: obj.videoChannels,
|
||||||
|
author: obj.author
|
||||||
|
}
|
||||||
const hashTokens = {
|
const hashTokens = {
|
||||||
accessToken: obj.access_token,
|
accessToken: obj.access_token,
|
||||||
tokenType: obj.token_type,
|
tokenType: obj.token_type,
|
||||||
refreshToken: obj.refresh_token
|
refreshToken: obj.refresh_token
|
||||||
}
|
}
|
||||||
|
|
||||||
this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens)
|
this.user = new AuthUser(hashUser, hashTokens)
|
||||||
this.user.save()
|
this.user.save()
|
||||||
|
|
||||||
this.setStatus(AuthStatus.LoggedIn)
|
this.setStatus(AuthStatus.LoggedIn)
|
||||||
|
|
|
@ -28,6 +28,13 @@ export const VIDEO_LANGUAGE = {
|
||||||
MESSAGES: {}
|
MESSAGES: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const VIDEO_CHANNEL = {
|
||||||
|
VALIDATORS: [ Validators.required ],
|
||||||
|
MESSAGES: {
|
||||||
|
'required': 'Video channel is required.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const VIDEO_DESCRIPTION = {
|
export const VIDEO_DESCRIPTION = {
|
||||||
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
|
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
|
||||||
MESSAGES: {
|
MESSAGES: {
|
||||||
|
|
|
@ -15,13 +15,6 @@ export class UserService {
|
||||||
private restExtractor: RestExtractor
|
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) {
|
changePassword (newPassword: string) {
|
||||||
const url = UserService.BASE_USERS_URL + 'me'
|
const url = UserService.BASE_USERS_URL + 'me'
|
||||||
const body: UserUpdateMe = {
|
const body: UserUpdateMe = {
|
||||||
|
|
|
@ -25,6 +25,18 @@
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="category">Channel</label>
|
||||||
|
<select class="form-control" id="channelId" formControlName="channelId">
|
||||||
|
<option></option>
|
||||||
|
<option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<div *ngIf="formErrors.channelId" class="alert alert-danger">
|
||||||
|
{{ formErrors.channelId }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="category">Category</label>
|
<label for="category">Category</label>
|
||||||
<select class="form-control" id="category" formControlName="category">
|
<select class="form-control" id="category" formControlName="category">
|
||||||
|
|
|
@ -12,9 +12,10 @@ import {
|
||||||
VIDEO_LANGUAGE,
|
VIDEO_LANGUAGE,
|
||||||
VIDEO_DESCRIPTION,
|
VIDEO_DESCRIPTION,
|
||||||
VIDEO_TAGS,
|
VIDEO_TAGS,
|
||||||
|
VIDEO_CHANNEL,
|
||||||
VIDEO_FILE
|
VIDEO_FILE
|
||||||
} from '../../shared'
|
} from '../../shared'
|
||||||
import { ServerService } from '../../core'
|
import { AuthService, ServerService } from '../../core'
|
||||||
import { VideoService } from '../shared'
|
import { VideoService } from '../shared'
|
||||||
import { VideoCreate } from '../../../../../shared'
|
import { VideoCreate } from '../../../../../shared'
|
||||||
import { HttpEventType, HttpResponse } from '@angular/common/http'
|
import { HttpEventType, HttpResponse } from '@angular/common/http'
|
||||||
|
@ -33,6 +34,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
videoCategories = []
|
videoCategories = []
|
||||||
videoLicences = []
|
videoLicences = []
|
||||||
videoLanguages = []
|
videoLanguages = []
|
||||||
|
userVideoChannels = []
|
||||||
|
|
||||||
tagValidators = VIDEO_TAGS.VALIDATORS
|
tagValidators = VIDEO_TAGS.VALIDATORS
|
||||||
tagValidatorsMessages = VIDEO_TAGS.MESSAGES
|
tagValidatorsMessages = VIDEO_TAGS.MESSAGES
|
||||||
|
@ -44,6 +46,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
category: '',
|
category: '',
|
||||||
licence: '',
|
licence: '',
|
||||||
language: '',
|
language: '',
|
||||||
|
channelId: '',
|
||||||
description: '',
|
description: '',
|
||||||
videofile: ''
|
videofile: ''
|
||||||
}
|
}
|
||||||
|
@ -52,6 +55,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
category: VIDEO_CATEGORY.MESSAGES,
|
category: VIDEO_CATEGORY.MESSAGES,
|
||||||
licence: VIDEO_LICENCE.MESSAGES,
|
licence: VIDEO_LICENCE.MESSAGES,
|
||||||
language: VIDEO_LANGUAGE.MESSAGES,
|
language: VIDEO_LANGUAGE.MESSAGES,
|
||||||
|
channelId: VIDEO_CHANNEL.MESSAGES,
|
||||||
description: VIDEO_DESCRIPTION.MESSAGES,
|
description: VIDEO_DESCRIPTION.MESSAGES,
|
||||||
videofile: VIDEO_FILE.MESSAGES
|
videofile: VIDEO_FILE.MESSAGES
|
||||||
}
|
}
|
||||||
|
@ -60,6 +64,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
|
private authService: AuthService,
|
||||||
private serverService: ServerService,
|
private serverService: ServerService,
|
||||||
private videoService: VideoService
|
private videoService: VideoService
|
||||||
) {
|
) {
|
||||||
|
@ -77,6 +82,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
category: [ '', VIDEO_CATEGORY.VALIDATORS ],
|
category: [ '', VIDEO_CATEGORY.VALIDATORS ],
|
||||||
licence: [ '', VIDEO_LICENCE.VALIDATORS ],
|
licence: [ '', VIDEO_LICENCE.VALIDATORS ],
|
||||||
language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
|
language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
|
||||||
|
channelId: [ this.userVideoChannels[0].id, VIDEO_CHANNEL.VALIDATORS ],
|
||||||
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
|
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
|
||||||
videofile: [ '', VIDEO_FILE.VALIDATORS ],
|
videofile: [ '', VIDEO_FILE.VALIDATORS ],
|
||||||
tags: [ '' ]
|
tags: [ '' ]
|
||||||
|
@ -90,6 +96,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
this.videoLicences = this.serverService.getVideoLicences()
|
this.videoLicences = this.serverService.getVideoLicences()
|
||||||
this.videoLanguages = this.serverService.getVideoLanguages()
|
this.videoLanguages = this.serverService.getVideoLanguages()
|
||||||
|
|
||||||
|
const user = this.authService.getUser()
|
||||||
|
this.userVideoChannels = user.videoChannels.map(v => ({ id: v.id, label: v.name }))
|
||||||
|
|
||||||
this.buildForm()
|
this.buildForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +131,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
const category = formValue.category
|
const category = formValue.category
|
||||||
const licence = formValue.licence
|
const licence = formValue.licence
|
||||||
const language = formValue.language
|
const language = formValue.language
|
||||||
|
const channelId = formValue.channelId
|
||||||
const description = formValue.description
|
const description = formValue.description
|
||||||
const tags = formValue.tags
|
const tags = formValue.tags
|
||||||
const videofile = this.videofileInput.nativeElement.files[0]
|
const videofile = this.videofileInput.nativeElement.files[0]
|
||||||
|
@ -131,6 +141,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
||||||
formData.append('category', '' + category)
|
formData.append('category', '' + category)
|
||||||
formData.append('nsfw', '' + nsfw)
|
formData.append('nsfw', '' + nsfw)
|
||||||
formData.append('licence', '' + licence)
|
formData.append('licence', '' + licence)
|
||||||
|
formData.append('channelId', '' + channelId)
|
||||||
formData.append('videofile', videofile)
|
formData.append('videofile', videofile)
|
||||||
|
|
||||||
// Language is optional
|
// Language is optional
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'
|
import { Component, OnDestroy, OnInit } from '@angular/core'
|
||||||
import { ActivatedRoute, Router } from '@angular/router'
|
import { ActivatedRoute, Router } from '@angular/router'
|
||||||
import { Subscription } from 'rxjs/Subscription'
|
import { Subscription } from 'rxjs/Subscription'
|
||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
|
||||||
|
@ -11,7 +11,6 @@ import {
|
||||||
VideoService,
|
VideoService,
|
||||||
VideoPagination
|
VideoPagination
|
||||||
} from '../shared'
|
} from '../shared'
|
||||||
import { AuthService, AuthUser } from '../../core'
|
|
||||||
import { Search, SearchField, SearchService } from '../../shared'
|
import { Search, SearchField, SearchService } from '../../shared'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -27,7 +26,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
|
||||||
totalItems: null
|
totalItems: null
|
||||||
}
|
}
|
||||||
sort: SortField
|
sort: SortField
|
||||||
user: AuthUser = null
|
|
||||||
videos: Video[] = []
|
videos: Video[] = []
|
||||||
|
|
||||||
private search: Search
|
private search: Search
|
||||||
|
@ -36,8 +34,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private authService: AuthService,
|
|
||||||
private changeDetector: ChangeDetectorRef,
|
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private videoService: VideoService,
|
private videoService: VideoService,
|
||||||
|
@ -45,10 +41,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
if (this.authService.isLoggedIn()) {
|
|
||||||
this.user = AuthUser.load()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe to route changes
|
// Subscribe to route changes
|
||||||
this.subActivatedRoute = this.route.params.subscribe(routeParams => {
|
this.subActivatedRoute = this.route.params.subscribe(routeParams => {
|
||||||
this.loadRouteParams(routeParams)
|
this.loadRouteParams(routeParams)
|
||||||
|
|
|
@ -221,11 +221,11 @@ describe('Test advanced friends', function () {
|
||||||
// Pod 4 is friend with : 2 3
|
// Pod 4 is friend with : 2 3
|
||||||
// Pod 6 is friend with : 2 3
|
// Pod 6 is friend with : 2 3
|
||||||
it('Should make friends between pod 1, 2, 3 and 6 and exchange their videos', async function () {
|
it('Should make friends between pod 1, 2, 3 and 6 and exchange their videos', async function () {
|
||||||
this.timeout(20000)
|
this.timeout(30000)
|
||||||
|
|
||||||
await makeFriendsWrapper(1)
|
await makeFriendsWrapper(1)
|
||||||
|
|
||||||
await wait(11000)
|
await wait(22000)
|
||||||
|
|
||||||
const res = await getVideosWrapper(1)
|
const res = await getVideosWrapper(1)
|
||||||
const videos = res.body.data
|
const videos = res.body.data
|
||||||
|
|
Loading…
Reference in New Issue