Add channels to upload form

pull/125/head
Chocobozzz 2017-10-25 17:31:11 +02:00
parent d412e80e5f
commit bcd9f81eff
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 72 additions and 41 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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<User>(AuthService.BASE_USER_INFORMATION_URL, { headers })
return this.http.get<UserServerModel>(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)

View File

@ -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: {

View File

@ -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 = {

View File

@ -25,6 +25,18 @@
>
</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">
<label for="category">Category</label>
<select class="form-control" id="category" formControlName="category">

View File

@ -12,9 +12,10 @@ import {
VIDEO_LANGUAGE,
VIDEO_DESCRIPTION,
VIDEO_TAGS,
VIDEO_CHANNEL,
VIDEO_FILE
} from '../../shared'
import { ServerService } from '../../core'
import { AuthService, ServerService } from '../../core'
import { VideoService } from '../shared'
import { VideoCreate } from '../../../../../shared'
import { HttpEventType, HttpResponse } from '@angular/common/http'
@ -33,6 +34,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
videoCategories = []
videoLicences = []
videoLanguages = []
userVideoChannels = []
tagValidators = VIDEO_TAGS.VALIDATORS
tagValidatorsMessages = VIDEO_TAGS.MESSAGES
@ -44,6 +46,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
category: '',
licence: '',
language: '',
channelId: '',
description: '',
videofile: ''
}
@ -52,6 +55,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
category: VIDEO_CATEGORY.MESSAGES,
licence: VIDEO_LICENCE.MESSAGES,
language: VIDEO_LANGUAGE.MESSAGES,
channelId: VIDEO_CHANNEL.MESSAGES,
description: VIDEO_DESCRIPTION.MESSAGES,
videofile: VIDEO_FILE.MESSAGES
}
@ -60,6 +64,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
private formBuilder: FormBuilder,
private router: Router,
private notificationsService: NotificationsService,
private authService: AuthService,
private serverService: ServerService,
private videoService: VideoService
) {
@ -77,6 +82,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
category: [ '', VIDEO_CATEGORY.VALIDATORS ],
licence: [ '', VIDEO_LICENCE.VALIDATORS ],
language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
channelId: [ this.userVideoChannels[0].id, VIDEO_CHANNEL.VALIDATORS ],
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
videofile: [ '', VIDEO_FILE.VALIDATORS ],
tags: [ '' ]
@ -90,6 +96,9 @@ export class VideoAddComponent extends FormReactive implements OnInit {
this.videoLicences = this.serverService.getVideoLicences()
this.videoLanguages = this.serverService.getVideoLanguages()
const user = this.authService.getUser()
this.userVideoChannels = user.videoChannels.map(v => ({ id: v.id, label: v.name }))
this.buildForm()
}
@ -122,6 +131,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
const category = formValue.category
const licence = formValue.licence
const language = formValue.language
const channelId = formValue.channelId
const description = formValue.description
const tags = formValue.tags
const videofile = this.videofileInput.nativeElement.files[0]
@ -131,6 +141,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
formData.append('category', '' + category)
formData.append('nsfw', '' + nsfw)
formData.append('licence', '' + licence)
formData.append('channelId', '' + channelId)
formData.append('videofile', videofile)
// Language is optional

View File

@ -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 { Subscription } from 'rxjs/Subscription'
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
@ -11,7 +11,6 @@ import {
VideoService,
VideoPagination
} from '../shared'
import { AuthService, AuthUser } from '../../core'
import { Search, SearchField, SearchService } from '../../shared'
@Component({
@ -27,7 +26,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
totalItems: null
}
sort: SortField
user: AuthUser = null
videos: Video[] = []
private search: Search
@ -36,8 +34,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
constructor (
private notificationsService: NotificationsService,
private authService: AuthService,
private changeDetector: ChangeDetectorRef,
private router: Router,
private route: ActivatedRoute,
private videoService: VideoService,
@ -45,10 +41,6 @@ export class VideoListComponent implements OnInit, OnDestroy {
) {}
ngOnInit () {
if (this.authService.isLoggedIn()) {
this.user = AuthUser.load()
}
// Subscribe to route changes
this.subActivatedRoute = this.route.params.subscribe(routeParams => {
this.loadRouteParams(routeParams)

View File

@ -221,11 +221,11 @@ describe('Test advanced friends', function () {
// Pod 4 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 () {
this.timeout(20000)
this.timeout(30000)
await makeFriendsWrapper(1)
await wait(11000)
await wait(22000)
const res = await getVideosWrapper(1)
const videos = res.body.data