From 7a08ba43e2dc55d7c207f091700676cb886984ad Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 29 May 2018 14:19:28 +0000 Subject: [PATCH 1/9] user settings: enable locking/unlocking an account --- src/components/user_settings/user_settings.js | 4 +++- src/components/user_settings/user_settings.vue | 4 ++++ src/i18n/messages.js | 3 ++- src/services/api/api.service.js | 6 ++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index b6026e18a4..443e63dd2d 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -5,6 +5,7 @@ const UserSettings = { return { newname: this.$store.state.users.currentUser.name, newbio: this.$store.state.users.currentUser.description, + newlocked: this.$store.state.users.currentUser.locked, followList: null, followImportError: false, followsImported: false, @@ -34,7 +35,8 @@ const UserSettings = { updateProfile () { const name = this.newname const description = this.newbio - this.$store.state.api.backendInteractor.updateProfile({params: {name, description}}).then((user) => { + const locked = this.newlocked + this.$store.state.api.backendInteractor.updateProfile({params: {name, description, locked}}).then((user) => { if (!user.error) { this.$store.commit('addNewUsers', [user]) this.$store.commit('setCurrentUser', user) diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index fbf3f651e7..4abdfc8e85 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -10,6 +10,10 @@

{{$t('settings.bio')}}

+
+ + +
diff --git a/src/i18n/messages.js b/src/i18n/messages.js index 54a99b5ab4..3e842af822 100644 --- a/src/i18n/messages.js +++ b/src/i18n/messages.js @@ -302,7 +302,8 @@ const en = { new_password: 'New password', confirm_new_password: 'Confirm new password', changed_password: 'Password changed successfully!', - change_password_error: 'There was an issue changing your password.' + change_password_error: 'There was an issue changing your password.', + lock_account_description: 'Restrict your account to approved followers only' }, notifications: { notifications: 'Notifications', diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 65761aee97..b50038b371 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -127,11 +127,13 @@ const updateBanner = ({credentials, params}) => { const updateProfile = ({credentials, params}) => { let url = PROFILE_UPDATE_URL + console.log(params) + const form = new FormData() each(params, (value, key) => { - if (key === 'description' || /* Always include description, because it might be empty */ - value) { + /* Always include description and locked, because it might be empty or false */ + if (key === 'description' || key === 'locked' || value) { form.append(key, value) } }) From 4e64514aa93d55c95f0c9d47d12fe88afa0b1a51 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Jun 2018 22:26:24 +0000 Subject: [PATCH 2/9] api: add fetchFollowRequests() --- src/services/api/api.service.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index b50038b371..22d5ce85aa 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -32,6 +32,7 @@ const USER_URL = '/api/users/show.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' +const FOLLOW_REQUESTS_URL = '/api/pleroma/friend_requests' import { each, map } from 'lodash' import 'whatwg-fetch' @@ -242,6 +243,12 @@ const fetchAllFollowing = ({username, credentials}) => { .then((data) => data.json()) } +const fetchFollowRequests = ({credentials}) => { + const url = FOLLOW_REQUESTS_URL + return fetch(url, { headers: authHeaders(credentials) }) + .then((data) => data.json()) +} + const fetchConversation = ({id, credentials}) => { let url = `${CONVERSATION_URL}/${id}.json?count=100` return fetch(url, { headers: authHeaders(credentials) }) @@ -442,7 +449,8 @@ const apiService = { externalProfile, followImport, deleteAccount, - changePassword + changePassword, + fetchFollowRequests } export default apiService From 4efb528a52813cacb29a42667501178556787d7b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Jun 2018 22:29:02 +0000 Subject: [PATCH 3/9] backend interactor service: implement fetchFollowRequests() --- .../backend_interactor_service/backend_interactor_service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 1417355805..b7f9340834 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -51,6 +51,7 @@ const backendInteractorService = (credentials) => { } const fetchMutes = () => apiService.fetchMutes({credentials}) + const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials}) const register = (params) => apiService.register(params) const updateAvatar = ({params}) => apiService.updateAvatar({credentials, params}) @@ -87,7 +88,8 @@ const backendInteractorService = (credentials) => { externalProfile, followImport, deleteAccount, - changePassword + changePassword, + fetchFollowRequests } return backendInteractorServiceInstance From 2cf28acfd14a52ec8cb3a3e514a4567653cb7610 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 00:29:01 +0000 Subject: [PATCH 4/9] api: add approveUser and denyUser functions --- src/services/api/api.service.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 22d5ce85aa..e39ab7285d 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -33,6 +33,8 @@ const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' const FOLLOW_REQUESTS_URL = '/api/pleroma/friend_requests' +const APPROVE_USER_URL = '/api/pleroma/friendships/approve' +const DENY_USER_URL = '/api/pleroma/friendships/deny' import { each, map } from 'lodash' import 'whatwg-fetch' @@ -219,6 +221,22 @@ const unblockUser = ({id, credentials}) => { }).then((data) => data.json()) } +const approveUser = ({id, credentials}) => { + let url = `${APPROVE_USER_URL}?user_id=${id}` + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + +const denyUser = ({id, credentials}) => { + let url = `${DENY_USER_URL}?user_id=${id}` + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + const fetchUser = ({id, credentials}) => { let url = `${USER_URL}?user_id=${id}` return fetch(url, { headers: authHeaders(credentials) }) @@ -450,7 +468,9 @@ const apiService = { followImport, deleteAccount, changePassword, - fetchFollowRequests + fetchFollowRequests, + approveUser, + denyUser } export default apiService From b8d0a6a0baba2fa560cdb3a13ca8135eba7d2255 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 00:29:13 +0000 Subject: [PATCH 5/9] backend interactor service: add approveUser and denyUser functions --- .../backend_interactor_service.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index b7f9340834..dbfb54f942 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -42,6 +42,14 @@ const backendInteractorService = (credentials) => { return apiService.unblockUser({credentials, id}) } + const approveUser = (id) => { + return apiService.approveUser({credentials, id}) + } + + const denyUser = (id) => { + return apiService.denyUser({credentials, id}) + } + const startFetching = ({timeline, store, userId = false}) => { return timelineFetcherService.startFetching({timeline, store, credentials, userId}) } @@ -89,7 +97,9 @@ const backendInteractorService = (credentials) => { followImport, deleteAccount, changePassword, - fetchFollowRequests + fetchFollowRequests, + approveUser, + denyUser } return backendInteractorServiceInstance From f3a27764aaf31a434c3f858668aa97e6c7328011 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 00:58:44 +0000 Subject: [PATCH 6/9] add follow requests UI --- .../follow_requests/follow_requests.js | 18 ++++++++++++++++++ .../follow_requests/follow_requests.vue | 12 ++++++++++++ src/components/nav_panel/nav_panel.vue | 5 +++++ src/components/user_card/user_card.js | 9 ++++++++- src/components/user_card/user_card.vue | 11 +++++++++++ src/i18n/messages.js | 7 +++++-- src/main.js | 2 ++ 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/components/follow_requests/follow_requests.js create mode 100644 src/components/follow_requests/follow_requests.vue diff --git a/src/components/follow_requests/follow_requests.js b/src/components/follow_requests/follow_requests.js new file mode 100644 index 0000000000..9fe4a57e19 --- /dev/null +++ b/src/components/follow_requests/follow_requests.js @@ -0,0 +1,18 @@ +import UserCard from '../user_card/user_card.vue' + +const FollowRequests = { + data () { + return { + requests: [] + } + }, + components: { + UserCard + }, + created () { + this.$store.state.api.backendInteractor.fetchFollowRequests() + .then((requests) => { this.requests = requests }) + } +} + +export default FollowRequests diff --git a/src/components/follow_requests/follow_requests.vue b/src/components/follow_requests/follow_requests.vue new file mode 100644 index 0000000000..87dc419414 --- /dev/null +++ b/src/components/follow_requests/follow_requests.vue @@ -0,0 +1,12 @@ + + + diff --git a/src/components/nav_panel/nav_panel.vue b/src/components/nav_panel/nav_panel.vue index 2e1a6c7a1f..0b188f9a15 100644 --- a/src/components/nav_panel/nav_panel.vue +++ b/src/components/nav_panel/nav_panel.vue @@ -12,6 +12,11 @@ {{ $t("nav.mentions") }} +
  • + + {{ $t("nav.friend_requests") }} + +
  • {{ $t("nav.public_tl") }} diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index a7a871c355..f47df0ebc9 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -3,7 +3,8 @@ import UserCardContent from '../user_card_content/user_card_content.vue' const UserCard = { props: [ 'user', - 'showFollows' + 'showFollows', + 'showApproval' ], data () { return { @@ -16,6 +17,12 @@ const UserCard = { methods: { toggleUserExpanded () { this.userExpanded = !this.userExpanded + }, + approveUser () { + this.$store.state.api.backendInteractor.approveUser(this.user.id) + }, + denyUser () { + this.$store.state.api.backendInteractor.denyUser(this.user.id) } } } diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 51d6965fed..6478a65fe3 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -15,6 +15,10 @@
  • @{{ user.screen_name }}
    +
    + + +
    @@ -75,4 +79,11 @@ margin-bottom: 0; } } + +.approval { + button { + width: 100%; + margin-bottom: 0.5em; + } +} diff --git a/src/i18n/messages.js b/src/i18n/messages.js index 3e842af822..6f56e8b712 100644 --- a/src/i18n/messages.js +++ b/src/i18n/messages.js @@ -218,7 +218,8 @@ const en = { timeline: 'Timeline', mentions: 'Mentions', public_tl: 'Public Timeline', - twkn: 'The Whole Known Network' + twkn: 'The Whole Known Network', + friend_requests: 'Follow Requests' }, user_card: { follows_you: 'Follows you!', @@ -232,7 +233,9 @@ const en = { followers: 'Followers', followees: 'Following', per_day: 'per day', - remote_follow: 'Remote follow' + remote_follow: 'Remote follow', + approve: 'Approve', + deny: 'Deny' }, timeline: { show_new: 'Show new', diff --git a/src/main.js b/src/main.js index 3c4a072be9..6b1262bef8 100644 --- a/src/main.js +++ b/src/main.js @@ -12,6 +12,7 @@ import UserProfile from './components/user_profile/user_profile.vue' import Settings from './components/settings/settings.vue' import Registration from './components/registration/registration.vue' import UserSettings from './components/user_settings/user_settings.vue' +import FollowRequests from './components/follow_requests/follow_requests.vue' import statusesModule from './modules/statuses.js' import usersModule from './modules/users.js' @@ -117,6 +118,7 @@ window.fetch('/static/config.json') { name: 'mentions', path: '/:username/mentions', component: Mentions }, { name: 'settings', path: '/settings', component: Settings }, { name: 'registration', path: '/registration', component: Registration }, + { name: 'friend-requests', path: '/friend-requests', component: FollowRequests }, { name: 'user-settings', path: '/user-settings', component: UserSettings } ] From fd25f6874193fb9413f14be17f7c6e567a3b8a28 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 01:13:58 +0000 Subject: [PATCH 7/9] config: fix typo --- config/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/index.js b/config/index.js index c48d91b8bc..5d2cb83398 100644 --- a/config/index.js +++ b/config/index.js @@ -23,12 +23,12 @@ module.exports = { assetsPublicPath: '/', proxyTable: { '/api': { - target: 'htts://localhost:4000/', + target: 'http://localhost:4000/', changeOrigin: true, cookieDomainRewrite: 'localhost' }, '/socket': { - target: 'htts://localhost:4000/', + target: 'http://localhost:4000/', changeOrigin: true, cookieDomainRewrite: 'localhost', ws: true From 7389f071151d271187b3236a4f56ebfdc018c289 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 01:24:31 +0000 Subject: [PATCH 8/9] follow requests: refactor to properly leverage vuex --- .../follow_requests/follow_requests.js | 19 ++++++++++++------- src/components/user_card/user_card.js | 2 ++ src/modules/api.js | 10 +++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/follow_requests/follow_requests.js b/src/components/follow_requests/follow_requests.js index 9fe4a57e19..11a228aa4b 100644 --- a/src/components/follow_requests/follow_requests.js +++ b/src/components/follow_requests/follow_requests.js @@ -1,17 +1,22 @@ import UserCard from '../user_card/user_card.vue' const FollowRequests = { - data () { - return { - requests: [] - } - }, components: { UserCard }, created () { - this.$store.state.api.backendInteractor.fetchFollowRequests() - .then((requests) => { this.requests = requests }) + this.updateRequests() + }, + computed: { + requests () { + return this.$store.state.api.followRequests + } + }, + methods: { + updateRequests () { + this.$store.state.api.backendInteractor.fetchFollowRequests() + .then((requests) => { this.$store.commit('setFollowRequests', requests) }) + } } } diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index f47df0ebc9..a019627a8b 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -20,9 +20,11 @@ const UserCard = { }, approveUser () { this.$store.state.api.backendInteractor.approveUser(this.user.id) + this.$store.dispatch('removeFollowRequest', this.user) }, denyUser () { this.$store.state.api.backendInteractor.denyUser(this.user.id) + this.$store.dispatch('removeFollowRequest', this.user) } } } diff --git a/src/modules/api.js b/src/modules/api.js index c91fb97bbc..a61340c223 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -7,7 +7,8 @@ const api = { backendInteractor: backendInteractorService(), fetchers: {}, socket: null, - chatDisabled: false + chatDisabled: false, + followRequests: [] }, mutations: { setBackendInteractor (state, backendInteractor) { @@ -24,6 +25,9 @@ const api = { }, setChatDisabled (state, value) { state.chatDisabled = value + }, + setFollowRequests (state, value) { + state.followRequests = value } }, actions: { @@ -57,6 +61,10 @@ const api = { }, disableChat (store) { store.commit('setChatDisabled', true) + }, + removeFollowRequest (store, request) { + let requests = store.state.followRequests.filter((it) => it !== request) + store.commit('setFollowRequests', requests) } } } From d7d787b84cb8e36ad7f622054808f0e66c496309 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 02:16:30 +0000 Subject: [PATCH 9/9] user card: show that the account is locked if it is --- src/components/user_card_content/user_card_content.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index c120df9a66..09e91271bf 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -15,7 +15,7 @@
    {{user.name}}
    - @{{user.screen_name}} + @{{user.screen_name}} {{dailyAvg}} {{ $t('user_card.per_day') }}