ActivityPub-federated video streaming platform using P2P directly in your web browser
Add ability to update the user display name/description
Chocobozzzed56ad1193bb
diff --git a/client/src/app/menu/menu.component.html b/client/src/app/menu/menu.component.htmlindex 6e81893713..d1488ec3c3 100644--- a/client/src/app/menu/menu.component.html+++ b/client/src/app/menu/menu.component.html@@ -5,7 +5,7 @@</a><div class="logged-in-info">- <a routerLink="/my-account/settings" class="logged-in-username">{{ user.username }}</a>+ <a routerLink="/my-account/settings" class="logged-in-username">{{ user.account?.displayName }}</a><div class="logged-in-email">{{ user.email }}</div></div>@@ -14,8 +14,8 @@<ul *dropdownMenu class="dropdown-menu"><li>- <a i18n routerLink="/my-account/settings" class="dropdown-item" title="My account">- My account+ <a routerLink="/my-account/settings" class="dropdown-item" title="My settings">+ My settings</a><a (click)="logout($event)" class="dropdown-item" title="Log out" href="#">diff --git a/client/src/app/my-account/my-account-settings/my-account-details/index.ts b/client/src/app/my-account/my-account-settings/my-account-details/index.tsdeleted file mode 100644index b7f58e3292..0000000000--- a/client/src/app/my-account/my-account-settings/my-account-details/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from './my-account-details.component'diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/index.ts b/client/src/app/my-account/my-account-settings/my-account-profile/index.tsnew file mode 100644index 0000000000..3cc049f8ff--- /dev/null+++ b/client/src/app/my-account/my-account-settings/my-account-profile/index.ts@@ -0,0 +1 @@+export * from './my-account-profile.component'diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.htmlnew file mode 100644index 0000000000..306f3a12c8--- /dev/null+++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html@@ -0,0 +1,24 @@+<div *ngIf="error" class="alert alert-danger">{{ error }}</div>++<form role="form" (ngSubmit)="updateMyProfile()" [formGroup]="form">++ <label for="display-name">Display name</label>+ <input+ type="text" id="display-name"+ formControlName="display-name" [ngClass]="{ 'input-error': formErrors['display-name'] }"+ >+ <div *ngIf="formErrors['display-name']" class="form-error">+ {{ formErrors['display-name'] }}+ </div>++ <label for="description">Description</label>+ <textarea+ id="description" formControlName="description"+ [ngClass]="{ 'input-error': formErrors['description'] }"+ ></textarea>+ <div *ngIf="formErrors.description" class="form-error">+ {{ formErrors.description }}+ </div>++ <input type="submit" value="Update my profile" [disabled]="!form.valid">+</form>diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scssnew file mode 100644index 0000000000..fc2b92c89c--- /dev/null+++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss@@ -0,0 +1,23 @@+@import '_variables';+@import '_mixins';++input[type=text] {+ @include peertube-input-text(340px);++ display: block;+ margin-bottom: 15px;+}++textarea {+ @include peertube-textarea(500px, 150px);++ display: block;+}++input[type=submit] {+ @include peertube-button;+ @include orange-button;++ margin-top: 15px;+}+diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.tsnew file mode 100644index 0000000000..2b7ba353c1--- /dev/null+++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts@@ -0,0 +1,65 @@+import { Component, Input, OnInit } from '@angular/core'+import { FormBuilder, FormGroup } from '@angular/forms'+import { NotificationsService } from 'angular2-notifications'+import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared'+import { User } from '@app/shared'++@Component({+ selector: 'my-account-profile',+ templateUrl: './my-account-profile.component.html',+ styleUrls: [ './my-account-profile.component.scss' ]+})+export class MyAccountProfileComponent extends FormReactive implements OnInit {+ @Input() user: User = null++ error: string = null++ form: FormGroup+ formErrors = {+ 'display-name': '',+ 'description': ''+ }+ validationMessages = {+ 'display-name': USER_DISPLAY_NAME.MESSAGES,+ 'description': USER_DESCRIPTION.MESSAGES+ }++ constructor (+ private formBuilder: FormBuilder,+ private notificationsService: NotificationsService,+ private userService: UserService+ ) {+ super()+ }++ buildForm () {+ this.form = this.formBuilder.group({+ 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ],+ 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ]+ })++ this.form.valueChanges.subscribe(data => this.onValueChanged(data))+ }++ ngOnInit () {+ this.buildForm()+ }++ updateMyProfile () {+ const displayName = this.form.value['display-name']+ const description = this.form.value['description']++ this.error = null++ this.userService.updateMyProfile({ displayName, description }).subscribe(+ () => {+ this.user.account.displayName = displayName+ this.user.account.description = description++ this.notificationsService.success('Success', 'Profile updated.')+ },++ err => this.error = err.message+ )+ }+}diff --git a/client/src/app/my-account/my-account-settings/my-account-settings.component.html b/client/src/app/my-account/my-account-settings/my-account-settings.component.htmlindex e11d93c01d..e655b9d96a 100644--- a/client/src/app/my-account/my-account-settings/my-account-settings.component.html+++ b/client/src/app/my-account/my-account-settings/my-account-settings.component.html@@ -17,8 +17,13 @@<span class="user-quota-label">Video quota:</span> {{ userVideoQuotaUsed | bytes: 0 }} / {{ userVideoQuota }}</div>-<div class="account-title">Account settings</div>+<ng-template [ngIf]="user && user.account">+ <div class="account-title">Profile</div>+ <my-account-profile [user]="user"></my-account-profile>+</ng-template>++<div class="account-title">Password</div><my-account-change-password></my-account-change-password><div class="account-title">Video settings</div>-<my-account-details [user]="user"></my-account-details>+<my-account-video-settings [user]="user"></my-account-video-settings>diff --git a/client/src/app/my-account/my-account-settings/my-account-video-settings/index.ts b/client/src/app/my-account/my-account-settings/my-account-video-settings/index.tsnew file mode 100644index 0000000000..1253bd3691--- /dev/null+++ b/client/src/app/my-account/my-account-settings/my-account-video-settings/index.ts@@ -0,0 +1 @@+export * from './my-account-video-settings.component'diff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.html b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.htmlsimilarity index 100%rename from client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.htmlrename to client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.htmldiff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.scss b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scsssimilarity index 100%rename from client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.scssrename to client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scssdiff --git a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.ts b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.tssimilarity index 81%rename from client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.tsrename to client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.tsindex 4c14565414..acc70c14d7 100644--- a/client/src/app/my-account/my-account-settings/my-account-details/my-account-details.component.ts+++ b/client/src/app/my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts@@ -6,11 +6,11 @@ import { AuthService } from '../../../core'import { FormReactive, User, UserService } from '../../../shared'@Component({- selector: 'my-account-details',- templateUrl: './my-account-details.component.html',- styleUrls: [ './my-account-details.component.scss' ]+ selector: 'my-account-video-settings',+ templateUrl: './my-account-video-settings.component.html',+ styleUrls: [ './my-account-video-settings.component.scss' ]})-export class MyAccountDetailsComponent extends FormReactive implements OnInit {+export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit {@Input() user: User = nullform: FormGroup@@ -47,7 +47,7 @@ export class MyAccountDetailsComponent extends FormReactive implements OnInit {autoPlayVideo}- this.userService.updateMyDetails(details).subscribe(+ this.userService.updateMyProfile(details).subscribe(() => {this.notificationsService.success('Success', 'Information updated.')diff --git a/client/src/app/my-account/my-account.component.html b/client/src/app/my-account/my-account.component.htmlindex 637b2587cc..41afc1e5d2 100644--- a/client/src/app/my-account/my-account.component.html+++ b/client/src/app/my-account/my-account.component.html@@ -1,6 +1,6 @@<div class="row"><div class="sub-menu">- <a routerLink="/my-account/settings" routerLinkActive="active" class="title-page">My account</a>+ <a routerLink="/my-account/settings" routerLinkActive="active" class="title-page">My settings</a><a routerLink="/my-account/videos" routerLinkActive="active" class="title-page">My videos</a></div>diff --git a/client/src/app/my-account/my-account.module.ts b/client/src/app/my-account/my-account.module.tsindex 3172773049..981d3c6978 100644--- a/client/src/app/my-account/my-account.module.ts+++ b/client/src/app/my-account/my-account.module.ts@@ -2,10 +2,11 @@ import { NgModule } from '@angular/core'import { SharedModule } from '../shared'import { MyAccountRoutingModule } from './my-account-routing.module'import { MyAccountChangePasswordComponent } from './my-account-settings/my-account-change-password/my-account-change-password.component'-import { MyAccountDetailsComponent } from './my-account-settings/my-account-details/my-account-details.component'+import { MyAccountVideoSettingsComponent } from './my-account-settings/my-account-video-settings/my-account-video-settings.component'import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component'import { MyAccountComponent } from './my-account.component'import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.component'+import { MyAccountProfileComponent } from '@app/my-account/my-account-settings/my-account-profile/my-account-profile.component'@NgModule({imports: [@@ -17,7 +18,8 @@ import { MyAccountVideosComponent } from './my-account-videos/my-account-videos.MyAccountComponent,MyAccountSettingsComponent,MyAccountChangePasswordComponent,- MyAccountDetailsComponent,+ MyAccountVideoSettingsComponent,+ MyAccountProfileComponent,MyAccountVideosComponent],diff --git a/client/src/app/shared/forms/form-validators/user.ts b/client/src/app/shared/forms/form-validators/user.tsindex d2a28a2721..095b534c00 100644--- a/client/src/app/shared/forms/form-validators/user.ts+++ b/client/src/app/shared/forms/form-validators/user.ts@@ -46,3 +46,27 @@ export const USER_ROLE = {'required': 'User role is required.'}}+export const USER_DISPLAY_NAME = {+ VALIDATORS: [+ Validators.required,+ Validators.minLength(3),+ Validators.maxLength(120)+ ],+ MESSAGES: {+ 'required': 'Display name is required.',+ 'minlength': 'Display name must be at least 3 characters long.',+ 'maxlength': 'Display name cannot be more than 120 characters long.'+ }+}+export const USER_DESCRIPTION = {+ VALIDATORS: [+ Validators.required,+ Validators.minLength(3),+ Validators.maxLength(250)+ ],+ MESSAGES: {+ 'required': 'Display name is required.',+ 'minlength': 'Display name must be at least 3 characters long.',+ 'maxlength': 'Display name cannot be more than 250 characters long.'+ }+}diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.tsindex da7b583f4d..adb840ceca 100644--- a/client/src/app/shared/users/user.service.ts+++ b/client/src/app/shared/users/user.service.ts@@ -26,10 +26,10 @@ export class UserService {.catch(res => this.restExtractor.handleError(res))}- updateMyDetails (details: UserUpdateMe) {+ updateMyProfile (profile: UserUpdateMe) {const url = UserService.BASE_USERS_URL + 'me'- return this.authHttp.put(url, details)+ return this.authHttp.put(url, profile).map(this.restExtractor.extractDataBool).catch(res => this.restExtractor.handleError(res))}diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.tsindex dcc4ef196b..2342c23dd6 100644--- a/server/controllers/api/users.ts+++ b/server/controllers/api/users.ts@@ -303,6 +303,7 @@ async function updateMe (req: express.Request, res: express.Response, next: exprawait sequelizeTypescript.transaction(async t => {await user.save({ transaction: t })+ if (body.displayName !== undefined) user.Account.name = body.displayNameif (body.description !== undefined) user.Account.description = body.descriptionawait user.Account.save({ transaction: t })diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.tsindex c0acb8218b..b59b766def 100644--- a/server/helpers/custom-validators/users.ts+++ b/server/helpers/custom-validators/users.ts@@ -22,6 +22,10 @@ function isUserUsernameValid (value: string) {return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))}+function isUserDisplayNameValid (value: string) {+ return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.NAME))+}+function isUserDescriptionValid (value: string) {return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.DESCRIPTION))}@@ -60,6 +64,7 @@ export {isUserUsernameValid,isUserNSFWPolicyValid,isUserAutoPlayVideoValid,+ isUserDisplayNameValid,isUserDescriptionValid,isAvatarFile}diff --git a/server/initializers/constants.ts b/server/initializers/constants.tsindex 9c9c3afc09..365b8617df 100644--- a/server/initializers/constants.ts+++ b/server/initializers/constants.ts@@ -180,9 +180,10 @@ const CONFIG = {const CONSTRAINTS_FIELDS = {USERS: {+ NAME: { min: 3, max: 120 }, // Length+ DESCRIPTION: { min: 3, max: 250 }, // LengthUSERNAME: { min: 3, max: 20 }, // LengthPASSWORD: { min: 6, max: 255 }, // Length- DESCRIPTION: { min: 3, max: 250 }, // LengthVIDEO_QUOTA: { min: -1 }},VIDEO_ABUSES: {diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.tsindex 5dd8caa3f5..247b704c43 100644--- a/server/middlewares/validators/users.ts+++ b/server/middlewares/validators/users.ts@@ -7,7 +7,7 @@ import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'import {isAvatarFile,isUserAutoPlayVideoValid,- isUserDescriptionValid,+ isUserDescriptionValid, isUserDisplayNameValid,isUserNSFWPolicyValid,isUserPasswordValid,isUserRoleValid,@@ -98,6 +98,7 @@ const usersUpdateValidator = []const usersUpdateMeValidator = [+ body('displayName').optional().custom(isUserDisplayNameValid).withMessage('Should have a valid display name'),body('description').optional().custom(isUserDescriptionValid).withMessage('Should have a valid description'),body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'),body('email').optional().isEmail().withMessage('Should have a valid email attribute'),diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.tsindex a7f3aa8d35..8b9b63348c 100644--- a/server/tests/api/users/users-multiple-servers.ts+++ b/server/tests/api/users/users-multiple-servers.ts@@ -76,6 +76,22 @@ describe('Test users with multiple servers', function () {await wait(5000)})+ it('Should be able to update my display name', async function () {+ this.timeout(10000)++ await updateMyUser({+ url: servers[0].url,+ accessToken: servers[0].accessToken,+ displayName: 'my super display name'+ })++ const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)+ user = res.body+ expect(user.account.displayName).to.equal('my super display name')++ await wait(5000)+ })+it('Should be able to update my description', async function () {this.timeout(10000)@@ -87,6 +103,7 @@ describe('Test users with multiple servers', function () {const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)user = res.body+ expect(user.account.displayName).to.equal('my super display name')expect(user.account.description).to.equal('my super description updated')await wait(5000)@@ -111,7 +128,7 @@ describe('Test users with multiple servers', function () {await wait(5000)})- it('Should have updated my avatar and my description on other servers too', async function () {+ it('Should have updated my profile on other servers too', async function () {for (const server of servers) {const resAccounts = await getAccountsList(server.url, '-createdAt')@@ -122,6 +139,7 @@ describe('Test users with multiple servers', function () {const rootServer1Get = resAccount.body as Accountexpect(rootServer1Get.name).to.equal('root')expect(rootServer1Get.host).to.equal('localhost:9001')+ expect(rootServer1Get.displayName).to.equal('my super display name')expect(rootServer1Get.description).to.equal('my super description updated')await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.tsindex 1192ef9e4a..1ea5998593 100644--- a/server/tests/api/users/users.ts+++ b/server/tests/api/users/users.ts@@ -172,6 +172,7 @@ describe('Test users', function () {expect(user.videoQuota).to.equal(2 * 1024 * 1024)expect(user.roleLabel).to.equal('User')expect(user.id).to.be.a('number')+ expect(user.account.displayName).to.equal('user_1')expect(user.account.description).to.be.null})@@ -316,6 +317,7 @@ describe('Test users', function () {expect(user.nsfwPolicy).to.equal('do_not_list')expect(user.videoQuota).to.equal(2 * 1024 * 1024)expect(user.id).to.be.a('number')+ expect(user.account.displayName).to.equal('user_1')expect(user.account.description).to.be.null})@@ -347,6 +349,7 @@ describe('Test users', function () {expect(user.nsfwPolicy).to.equal('do_not_list')expect(user.videoQuota).to.equal(2 * 1024 * 1024)expect(user.id).to.be.a('number')+ expect(user.account.displayName).to.equal('user_1')expect(user.account.description).to.be.null})@@ -365,6 +368,25 @@ describe('Test users', function () {await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')})+ it('Should be able to update my display name', async function () {+ await updateMyUser({+ url: server.url,+ accessToken: accessTokenUser,+ displayName: 'new display name'+ })++ const res = await getMyUserInformation(server.url, accessTokenUser)+ const user = res.body++ expect(user.username).to.equal('user_1')+ expect(user.email).to.equal('[email protected]')+ expect(user.nsfwPolicy).to.equal('do_not_list')+ expect(user.videoQuota).to.equal(2 * 1024 * 1024)+ expect(user.id).to.be.a('number')+ expect(user.account.displayName).to.equal('new display name')+ expect(user.account.description).to.be.null+ })+it('Should be able to update my description', async function () {await updateMyUser({url: server.url,@@ -380,6 +402,7 @@ describe('Test users', function () {expect(user.nsfwPolicy).to.equal('do_not_list')expect(user.videoQuota).to.equal(2 * 1024 * 1024)expect(user.id).to.be.a('number')+ expect(user.account.displayName).to.equal('new display name')expect(user.account.description).to.equal('my super description updated')})diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.tsindex fc6b26c50a..d31e57a256 100644--- a/server/tests/utils/users/users.ts+++ b/server/tests/utils/users/users.ts@@ -132,6 +132,7 @@ function updateMyUser (options: {nsfwPolicy?: NSFWPolicyType,email?: string,autoPlayVideo?: boolean+ displayName?: string,description?: string}) {const path = '/api/v1/users/me'@@ -142,6 +143,7 @@ function updateMyUser (options: {if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideoif (options.email !== undefined && options.email !== null) toSend['email'] = options.emailif (options.description !== undefined && options.description !== null) toSend['description'] = options.description+ if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayNamereturn makePutBodyRequest({url: options.url,diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.tsindex 0a73879ed3..ddab837fe8 100644--- a/shared/models/users/user-update-me.model.ts+++ b/shared/models/users/user-update-me.model.ts@@ -1,6 +1,7 @@import { NSFWPolicyType } from '../videos/nsfw-policy.type'export interface UserUpdateMe {+ displayName?: stringdescription?: stringnsfwPolicy?: NSFWPolicyTypeautoPlayVideo?: boolean