From f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 10:53:54 +0100 Subject: Don't show videos of remote instance after unfollow --- server/controllers/api/accounts.ts | 4 ++-- server/controllers/api/jobs.ts | 7 +++++-- server/controllers/api/server/follows.ts | 6 +++--- server/controllers/api/users.ts | 22 ++++++++++++++-------- server/controllers/api/videos/abuse.ts | 4 ++-- server/controllers/api/videos/blacklist.ts | 4 ++-- server/controllers/api/videos/channel.ts | 4 ++-- server/controllers/api/videos/comment.ts | 4 ++-- server/controllers/api/videos/index.ts | 6 +++--- 9 files changed, 35 insertions(+), 26 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 3bc929db8..4dc0cc16d 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -1,6 +1,6 @@ import * as express from 'express' import { getFormattedObjects } from '../../helpers/utils' -import { asyncMiddleware, paginationValidator, setDefaultSort, setPagination } from '../../middlewares' +import { asyncMiddleware, paginationValidator, setDefaultSort, setDefaultPagination } from '../../middlewares' import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' import { AccountModel } from '../../models/account/account' @@ -10,7 +10,7 @@ accountsRouter.get('/', paginationValidator, accountsSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listAccounts) ) diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index 180a3fca6..de37dea39 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts @@ -1,7 +1,10 @@ import * as express from 'express' import { UserRight } from '../../../shared/models/users' import { getFormattedObjects } from '../../helpers/utils' -import { asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultSort, setPagination } from '../../middlewares' +import { + asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultPagination, + setDefaultSort +} from '../../middlewares' import { paginationValidator } from '../../middlewares/validators' import { JobModel } from '../../models/job/job' @@ -13,7 +16,7 @@ jobsRouter.get('/', paginationValidator, jobsSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listJobs) ) diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index 0fbcc4b80..40b62d977 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts @@ -10,7 +10,7 @@ import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/acto import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send' import { asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, setDefaultSort, - setPagination + setDefaultPagination } from '../../../middlewares' import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' import { ActorModel } from '../../../models/activitypub/actor' @@ -22,7 +22,7 @@ serverFollowsRouter.get('/following', paginationValidator, followingSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listFollowing) ) @@ -45,7 +45,7 @@ serverFollowsRouter.get('/followers', paginationValidator, followersSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listFollowers) ) diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 0ca9b337a..aced4639e 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -13,7 +13,7 @@ import { sendUpdateUser } from '../../lib/activitypub/send' import { createUserAccountAndChannel } from '../../lib/user' import { asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setDefaultSort, - setPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, + setDefaultPagination, token, usersAddValidator, usersGetValidator, usersRegisterValidator, usersRemoveValidator, usersSortValidator, usersUpdateMeValidator, usersUpdateValidator, usersVideoRatingValidator } from '../../middlewares' import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' @@ -40,7 +40,7 @@ usersRouter.get('/me/videos', paginationValidator, videosSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(getUserVideos) ) @@ -56,7 +56,7 @@ usersRouter.get('/', paginationValidator, usersSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listUsers) ) @@ -129,15 +129,19 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon errorMessage: 'Cannot insert the user with many retries.' } - await retryTransactionWrapper(createUser, options) + const { user, account } = await retryTransactionWrapper(createUser, options) - // TODO : include Location of the new user -> 201 - return res.type('json').status(204).end() + return res.json({ + user: { + id: user.id, + uuid: account.uuid + } + }).end() } async function createUser (req: express.Request) { const body: UserCreate = req.body - const user = new UserModel({ + const userToCreate = new UserModel({ username: body.username, password: body.password, email: body.email, @@ -147,9 +151,11 @@ async function createUser (req: express.Request) { videoQuota: body.videoQuota }) - await createUserAccountAndChannel(user) + const { user, account } = await createUserAccountAndChannel(userToCreate) logger.info('User %s with its channel and account created.', body.username) + + return { user, account } } async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 91594490b..61ff3af4f 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -6,7 +6,7 @@ import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' import { sendVideoAbuse } from '../../../lib/activitypub/send' import { - asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setPagination, videoAbuseReportValidator, + asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, setDefaultSort, setDefaultPagination, videoAbuseReportValidator, videoAbusesSortValidator } from '../../../middlewares' import { AccountModel } from '../../../models/account/account' @@ -21,7 +21,7 @@ abuseVideoRouter.get('/abuse', paginationValidator, videoAbusesSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listVideoAbuses) ) abuseVideoRouter.post('/:id/abuse', diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index c9087fd97..7eee460d4 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -3,7 +3,7 @@ import { BlacklistedVideo, UserRight } from '../../../../shared' import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { - asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setPagination, + asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setDefaultPagination, videosBlacklistAddValidator, videosBlacklistRemoveValidator } from '../../../middlewares' import { VideoBlacklistModel } from '../../../models/video/video-blacklist' @@ -23,7 +23,7 @@ blacklistRouter.get('/blacklist', paginationValidator, blacklistSortValidator, setBlacklistSort, - setPagination, + setDefaultPagination, asyncMiddleware(listBlacklist) ) diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 2012575c8..8ec53d9ae 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts @@ -7,7 +7,7 @@ import { sequelizeTypescript } from '../../../initializers' import { setAsyncActorKeys } from '../../../lib/activitypub' import { createVideoChannel } from '../../../lib/video-channel' import { - asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setPagination, + asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setDefaultPagination, videoChannelsAddValidator, videoChannelsGetValidator, videoChannelsRemoveValidator, videoChannelsSortValidator, videoChannelsUpdateValidator } from '../../../middlewares' @@ -20,7 +20,7 @@ videoChannelRouter.get('/channels', paginationValidator, videoChannelsSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listVideoChannels) ) diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 3c2727530..f8a669e35 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -6,7 +6,7 @@ import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' -import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination } from '../../../middlewares' +import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setDefaultPagination } from '../../../middlewares' import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' import { addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator, @@ -21,7 +21,7 @@ videoCommentRouter.get('/:videoId/comment-threads', paginationValidator, videoCommentThreadsSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listVideoCommentThreadsValidator), asyncMiddleware(listVideoThreads) ) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 6a7f1f184..c2fdb4f95 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -14,7 +14,7 @@ import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' import { - asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setPagination, videosAddValidator, videosGetValidator, + asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setDefaultPagination, videosAddValidator, videosGetValidator, videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator } from '../../../middlewares' import { TagModel } from '../../../models/video/tag' @@ -45,7 +45,7 @@ videosRouter.get('/', paginationValidator, videosSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(listVideos) ) videosRouter.get('/search', @@ -53,7 +53,7 @@ videosRouter.get('/search', paginationValidator, videosSortValidator, setDefaultSort, - setPagination, + setDefaultPagination, asyncMiddleware(searchVideos) ) videosRouter.put('/:id', -- cgit v1.2.3