Merge pull request #135 from nextcloud-gmbh/fix/do-not-follow-your-own-account

exception when following yourself
pull/142/head
Julius Härtl 2018-12-05 11:44:19 +01:00 zatwierdzone przez GitHub
commit 2059a5f6cd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 39 dodań i 14 usunięć

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class FollowSameAccountException extends \Exception {
}

Wyświetl plik

@ -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();

Wyświetl plik

@ -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,

Wyświetl plik

@ -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: () => {} }

Wyświetl plik

@ -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
}
}
}

Wyświetl plik

@ -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)
})
}
}