diff options
-rw-r--r-- | client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/users/index.ts | 1 | ||||
-rw-r--r-- | server/controllers/api/video-channel.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/actor.ts | 2 | ||||
-rw-r--r-- | server/middlewares/activitypub.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 11 | ||||
-rw-r--r-- | server/tests/api/check-params/video-channels.ts | 10 |
7 files changed, 31 insertions, 6 deletions
diff --git a/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts index 79ac07c93..81608d837 100644 --- a/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts +++ b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-create.component.ts | |||
@@ -63,7 +63,14 @@ export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelE | |||
63 | this.router.navigate([ '/my-account', 'video-channels' ]) | 63 | this.router.navigate([ '/my-account', 'video-channels' ]) |
64 | }, | 64 | }, |
65 | 65 | ||
66 | err => this.error = err.message | 66 | err => { |
67 | if (err.status === 409) { | ||
68 | this.error = this.i18n('This name already exists on this instance.') | ||
69 | return | ||
70 | } | ||
71 | |||
72 | this.error = err.message | ||
73 | } | ||
67 | ) | 74 | ) |
68 | } | 75 | } |
69 | 76 | ||
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 8b8ebcd23..0b0081520 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -34,7 +34,6 @@ import { | |||
34 | usersVerifyEmailValidator | 34 | usersVerifyEmailValidator |
35 | } from '../../../middlewares/validators' | 35 | } from '../../../middlewares/validators' |
36 | import { UserModel } from '../../../models/account/user' | 36 | import { UserModel } from '../../../models/account/user' |
37 | import { OAuthTokenModel } from '../../../models/oauth/oauth-token' | ||
38 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | 37 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
39 | import { meRouter } from './me' | 38 | import { meRouter } from './me' |
40 | import { deleteUserToken } from '../../../lib/oauth-model' | 39 | import { deleteUserToken } from '../../../lib/oauth-model' |
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 4ca5ba9bc..1fa842d9c 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -46,7 +46,7 @@ videoChannelRouter.get('/', | |||
46 | 46 | ||
47 | videoChannelRouter.post('/', | 47 | videoChannelRouter.post('/', |
48 | authenticate, | 48 | authenticate, |
49 | videoChannelsAddValidator, | 49 | asyncMiddleware(videoChannelsAddValidator), |
50 | asyncRetryTransactionMiddleware(addVideoChannel) | 50 | asyncRetryTransactionMiddleware(addVideoChannel) |
51 | ) | 51 | ) |
52 | 52 | ||
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index d37a695a7..45dd4443d 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -56,7 +56,7 @@ async function getOrCreateActorAndServerAndModel ( | |||
56 | // We don't have this actor in our database, fetch it on remote | 56 | // We don't have this actor in our database, fetch it on remote |
57 | if (!actor) { | 57 | if (!actor) { |
58 | const { result } = await fetchRemoteActor(actorUrl) | 58 | const { result } = await fetchRemoteActor(actorUrl) |
59 | if (result === undefined) throw new Error('Cannot fetch remote actor.') | 59 | if (result === undefined) throw new Error('Cannot fetch remote actor ' + actorUrl) |
60 | 60 | ||
61 | // Create the attributed to actor | 61 | // Create the attributed to actor |
62 | // In PeerTube a video channel is owned by an account | 62 | // In PeerTube a video channel is owned by an account |
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 12d5c22c5..d7f59be8c 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -18,7 +18,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) | |||
18 | try { | 18 | try { |
19 | actor = await getOrCreateActorAndServerAndModel(creator) | 19 | actor = await getOrCreateActorAndServerAndModel(creator) |
20 | } catch (err) { | 20 | } catch (err) { |
21 | logger.error('Cannot create remote actor and check signature.', { err }) | 21 | logger.warn('Cannot create remote actor %s and check signature.', creator, { err }) |
22 | return res.sendStatus(403) | 22 | return res.sendStatus(403) |
23 | } | 23 | } |
24 | 24 | ||
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 79587b028..56a347b39 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -14,6 +14,7 @@ import { UserModel } from '../../models/account/user' | |||
14 | import { VideoChannelModel } from '../../models/video/video-channel' | 14 | import { VideoChannelModel } from '../../models/video/video-channel' |
15 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
16 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | 16 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' |
17 | import { ActorModel } from '../../models/activitypub/actor' | ||
17 | 18 | ||
18 | const listVideoAccountChannelsValidator = [ | 19 | const listVideoAccountChannelsValidator = [ |
19 | param('accountName').exists().withMessage('Should have a valid account name'), | 20 | param('accountName').exists().withMessage('Should have a valid account name'), |
@@ -34,11 +35,19 @@ const videoChannelsAddValidator = [ | |||
34 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), | 35 | body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), |
35 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), | 36 | body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), |
36 | 37 | ||
37 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
38 | logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) | 39 | logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) |
39 | 40 | ||
40 | if (areValidationErrors(req, res)) return | 41 | if (areValidationErrors(req, res)) return |
41 | 42 | ||
43 | const actor = await ActorModel.loadLocalByName(req.body.name) | ||
44 | if (actor) { | ||
45 | res.status(409) | ||
46 | .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) | ||
47 | .end() | ||
48 | return false | ||
49 | } | ||
50 | |||
42 | return next() | 51 | return next() |
43 | } | 52 | } |
44 | ] | 53 | ] |
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index bcf4b7473..3a7942945 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts | |||
@@ -136,6 +136,16 @@ describe('Test video channels API validator', function () { | |||
136 | statusCodeExpected: 200 | 136 | statusCodeExpected: 200 |
137 | }) | 137 | }) |
138 | }) | 138 | }) |
139 | |||
140 | it('Should fail when adding a channel with the same username', async function () { | ||
141 | await makePostBodyRequest({ | ||
142 | url: server.url, | ||
143 | path: videoChannelPath, | ||
144 | token: server.accessToken, | ||
145 | fields: baseCorrectParams, | ||
146 | statusCodeExpected: 409 | ||
147 | }) | ||
148 | }) | ||
139 | }) | 149 | }) |
140 | 150 | ||
141 | describe('When updating a video channel', function () { | 151 | describe('When updating a video channel', function () { |