aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-15 17:38:48 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63 (patch)
tree01f1d3e8b51d20fc257e7c82dd75e03e3e02d349
parenta7d647c4403f8774106f485e8d9323158454e111 (diff)
downloadPeerTube-39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63.tar.gz
PeerTube-39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63.tar.zst
PeerTube-39fdb3c032875ab8c9a1e5e52f76d3baa0ac4e63.zip
Unfollow with host
-rw-r--r--client/src/app/+admin/follows/shared/follow.service.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts42
-rw-r--r--server/initializers/migrations/0130-video-channel-actor.ts4
-rw-r--r--server/lib/activitypub/process/process-follow.ts2
4 files changed, 5 insertions, 45 deletions
diff --git a/client/src/app/+admin/follows/shared/follow.service.ts b/client/src/app/+admin/follows/shared/follow.service.ts
index 3a430ff64..089be9d64 100644
--- a/client/src/app/+admin/follows/shared/follow.service.ts
+++ b/client/src/app/+admin/follows/shared/follow.service.ts
@@ -47,7 +47,7 @@ export class FollowService {
47 } 47 }
48 48
49 unfollow (follow: AccountFollow) { 49 unfollow (follow: AccountFollow) {
50 return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.id) 50 return this.authHttp.delete(FollowService.BASE_APPLICATION_URL + '/following/' + follow.following.host)
51 .map(this.restExtractor.extractDataBool) 51 .map(this.restExtractor.extractDataBool)
52 .catch(res => this.restExtractor.handleError(res)) 52 .catch(res => this.restExtractor.handleError(res))
53 } 53 }
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index bf42757c5..5930bd5da 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -1,8 +1,5 @@
1import * as Bluebird from 'bluebird'
2import { Response } from 'express'
3import * as validator from 'validator' 1import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS } from '../../../initializers' 2import { CONSTRAINTS_FIELDS } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor'
6import { isAccountNameValid } from '../accounts' 3import { isAccountNameValid } from '../accounts'
7import { exists, isUUIDValid } from '../misc' 4import { exists, isUUIDValid } from '../misc'
8import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' 5import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
@@ -88,40 +85,6 @@ function isActorAcceptActivityValid (activity: any) {
88 return isBaseActivityValid(activity, 'Accept') 85 return isBaseActivityValid(activity, 'Accept')
89} 86}
90 87
91function isActorIdExist (id: number | string, res: Response) {
92 let promise: Bluebird<ActorModel>
93
94 if (validator.isInt('' + id)) {
95 promise = ActorModel.load(+id)
96 } else { // UUID
97 promise = ActorModel.loadByUUID('' + id)
98 }
99
100 return isActorExist(promise, res)
101}
102
103function isLocalActorNameExist (name: string, res: Response) {
104 const promise = ActorModel.loadLocalByName(name)
105
106 return isActorExist(promise, res)
107}
108
109async function isActorExist (p: Bluebird<ActorModel>, res: Response) {
110 const actor = await p
111
112 if (!actor) {
113 res.status(404)
114 .send({ error: 'Actor not found' })
115 .end()
116
117 return false
118 }
119
120 res.locals.actor = actor
121
122 return true
123}
124
125// --------------------------------------------------------------------------- 88// ---------------------------------------------------------------------------
126 89
127export { 90export {
@@ -137,8 +100,5 @@ export {
137 isActorFollowActivityValid, 100 isActorFollowActivityValid,
138 isActorAcceptActivityValid, 101 isActorAcceptActivityValid,
139 isActorDeleteActivityValid, 102 isActorDeleteActivityValid,
140 isActorIdExist, 103 isActorNameValid
141 isLocalActorNameExist,
142 isActorNameValid,
143 isActorExist
144} 104}
diff --git a/server/initializers/migrations/0130-video-channel-actor.ts b/server/initializers/migrations/0130-video-channel-actor.ts
index 72a0daef7..0b665b0c7 100644
--- a/server/initializers/migrations/0130-video-channel-actor.ts
+++ b/server/initializers/migrations/0130-video-channel-actor.ts
@@ -167,12 +167,12 @@ async function up (utils: {
167 167
168 const query1 = `UPDATE "actorFollow" 168 const query1 = `UPDATE "actorFollow"
169 SET "actorId" = 169 SET "actorId" =
170 (SELECT "actorId" FROM account WHERE id = "actorFollow"."actorId")` 170 (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."actorId")`
171 await utils.sequelize.query(query1) 171 await utils.sequelize.query(query1)
172 172
173 const query2 = `UPDATE "actorFollow" 173 const query2 = `UPDATE "actorFollow"
174 SET "targetActorId" = 174 SET "targetActorId" =
175 (SELECT "actorId" FROM account WHERE id = "actorFollow"."actorId")` 175 (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."targetActorId")`
176 176
177 await utils.sequelize.query(query2) 177 await utils.sequelize.query(query2)
178 } 178 }
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index ec7a331f3..bc02d5043 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -62,5 +62,5 @@ async function follow (actor: ActorModel, targetActorURL: string) {
62 return sendAccept(actorFollow, t) 62 return sendAccept(actorFollow, t)
63 }) 63 })
64 64
65 logger.info('Actor uuid %s is followed by actor %s.', actor.url, targetActorURL) 65 logger.info('Actor %s is followed by actor %s.', actor.url, targetActorURL)
66} 66}