kopia lustrzana https://github.com/nextcloud/social
				
				
				
			Merge pull request #135 from nextcloud-gmbh/fix/do-not-follow-your-own-account
exception when following yourselfpull/142/head
						commit
						2059a5f6cd
					
				|  | @ -0,0 +1,8 @@ | |||
| <?php | ||||
| 
 | ||||
| namespace OCA\Social\Exceptions; | ||||
| 
 | ||||
| class FollowSameAccountException extends \Exception { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | @ -36,6 +36,7 @@ use OCA\Social\Db\FollowsRequest; | |||
| use OCA\Social\Exceptions\ActorDoesNotExistException; | ||||
| use OCA\Social\Exceptions\CacheActorDoesNotExistException; | ||||
| use OCA\Social\Exceptions\FollowDoesNotExistException; | ||||
| use OCA\Social\Exceptions\FollowSameAccountException; | ||||
| use OCA\Social\Exceptions\InvalidResourceException; | ||||
| use OCA\Social\Exceptions\RequestException; | ||||
| use OCA\Social\Exceptions\SocialAppConfigException; | ||||
|  | @ -121,9 +122,14 @@ class FollowService implements ICoreService { | |||
| 	 * @throws CacheActorDoesNotExistException | ||||
| 	 * @throws InvalidResourceException | ||||
| 	 * @throws UrlCloudException | ||||
| 	 * @throws FollowSameAccountException | ||||
| 	 */ | ||||
| 	public function followAccount(Person $actor, string $account) { | ||||
| 		$remoteActor = $this->personService->getFromAccount($account); | ||||
| 		if ($remoteActor->getId() === $actor->getId()) { | ||||
| 			throw new FollowSameAccountException("Don't follow yourself, be your own lead"); | ||||
| 		} | ||||
| 
 | ||||
| 		$follow = new Follow(); | ||||
| 		$follow->setUrlCloud($this->configService->getCloudAddress()); | ||||
| 		$follow->generateUniqueId(); | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ | |||
| 			<h2>{{ displayName }}</h2> | ||||
| 			<p>{{ accountInfo.account }}</p> | ||||
| 			<p v-if="accountInfo.website">Website: <a :href="accountInfo.website.value">{{ accountInfo.website.value }}</a></p> | ||||
| 			<template v-if="currentUser.uid !== accountInfo.preferredUsername"> | ||||
| 			<template v-if="cloudId !== accountInfo.account"> | ||||
| 				<button v-if="accountInfo.details && accountInfo.details.following" :class="{'icon-loading-small': followLoading}" | ||||
| 					@click="unfollow()" | ||||
| 					@mouseover="followingText=t('social', 'Unfollow')" @mouseleave="followingText=t('social', 'Following')"> | ||||
|  | @ -100,7 +100,11 @@ export default { | |||
| 	components: { | ||||
| 		Avatar | ||||
| 	}, | ||||
| 	mixins: [serverData, currentUser, follow], | ||||
| 	mixins: [ | ||||
| 		serverData, | ||||
| 		currentUser, | ||||
| 		follow | ||||
| 	], | ||||
| 	props: { | ||||
| 		uid: { | ||||
| 			type: String, | ||||
|  |  | |||
|  | @ -36,12 +36,14 @@ | |||
| 				<!-- TODO check where the html is coming from to avoid security issues --> | ||||
| 				<p v-html="item.summary" /> | ||||
| 			</div> | ||||
| 			<button v-if="item.details && item.details.following" :class="{'icon-loading-small': followLoading}" | ||||
| 				@click="unfollow()" | ||||
| 				@mouseover="followingText=t('social', 'Unfollow')" @mouseleave="followingText=t('social', 'Following')"> | ||||
| 			<span><span class="icon-checkmark" />{{ followingText }}</span></button> | ||||
| 			<button v-else-if="item.details" :class="{'icon-loading-small': followLoading}" class="primary" | ||||
| 				@click="follow"><span>{{ t('social', 'Follow') }}</span></button> | ||||
| 			<template v-if="cloudId !== item.account"> | ||||
| 				<button v-if="item.details && item.details.following" :class="{'icon-loading-small': followLoading}" | ||||
| 					@click="unfollow()" | ||||
| 					@mouseover="followingText=t('social', 'Unfollow')" @mouseleave="followingText=t('social', 'Following')"> | ||||
| 				<span><span class="icon-checkmark" />{{ followingText }}</span></button> | ||||
| 				<button v-else-if="item.details" :class="{'icon-loading-small': followLoading}" class="primary" | ||||
| 					@click="follow"><span>{{ t('social', 'Follow') }}</span></button> | ||||
| 			</template> | ||||
| 		</div> | ||||
| 	</div> | ||||
| </template> | ||||
|  | @ -49,6 +51,7 @@ | |||
| <script> | ||||
| import { Avatar } from 'nextcloud-vue' | ||||
| import follow from '../mixins/follow' | ||||
| import currentUser from '../mixins/currentUserMixin' | ||||
| 
 | ||||
| export default { | ||||
| 	name: 'UserEntry', | ||||
|  | @ -56,7 +59,8 @@ export default { | |||
| 		Avatar | ||||
| 	}, | ||||
| 	mixins: [ | ||||
| 		follow | ||||
| 		follow, | ||||
| 		currentUser | ||||
| 	], | ||||
| 	props: { | ||||
| 		item: { type: Object, default: () => {} } | ||||
|  |  | |||
|  | @ -26,13 +26,16 @@ export default { | |||
| 		serverData | ||||
| 	], | ||||
| 	computed: { | ||||
| 		currentUser: function() { | ||||
| 		currentUser() { | ||||
| 			return OC.getCurrentUser() | ||||
| 		}, | ||||
| 		socialId: function() { | ||||
| 		socialId() { | ||||
| 			return '@' + this.cloudId | ||||
| 		}, | ||||
| 		cloudId() { | ||||
| 			const url = document.createElement('a') | ||||
| 			url.setAttribute('href', this.serverData.cloudAddress) | ||||
| 			return '@' + OC.getCurrentUser().uid + '@' + url.hostname | ||||
| 			return this.currentUser.uid + '@' + url.hostname | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ export default { | |||
| 			}).catch((error) => { | ||||
| 				this.followLoading = false | ||||
| 				OC.Notification.showTemporary(`Failed to follow user ${this.item.account}`) | ||||
| 				console.error(`Failed to follow user ${this.item.account}`, error) | ||||
| 				console.error(`Failed to follow user ${this.item.account}`, error.response.data) | ||||
| 			}) | ||||
| 
 | ||||
| 		}, | ||||
|  | @ -63,7 +63,7 @@ export default { | |||
| 			}).catch((error) => { | ||||
| 				this.followLoading = false | ||||
| 				OC.Notification.showTemporary(`Failed to unfollow user ${this.item.account}`) | ||||
| 				console.error(`Failed to unfollow user ${this.item.account}`, error) | ||||
| 				console.error(`Failed to unfollow user ${this.item.account}`, error.response.data) | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Julius Härtl
						Julius Härtl