From 24eba26c5b34a6abedbafebab0ed9489f0fcccd6 Mon Sep 17 00:00:00 2001 From: Lambda Date: Tue, 25 Dec 2018 18:43:52 +0100 Subject: [PATCH 1/2] Restore old routes, enable user route as fallback. --- src/boot/routes.js | 58 ++++++------------- src/components/login_form/login_form.js | 2 +- .../oauth_callback/oauth_callback.js | 2 +- src/components/registration/registration.js | 4 +- src/components/user_settings/user_settings.js | 2 +- src/modules/instance.js | 4 +- src/services/new_api/oauth.js | 4 +- static/config.json | 4 +- test/unit/specs/boot/routes.spec.js | 10 +++- 9 files changed, 37 insertions(+), 53 deletions(-) diff --git a/src/boot/routes.js b/src/boot/routes.js index 8ea8cc7f..d349ec45 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -20,48 +20,24 @@ export default (store) => { redirect: _to => { return (store.state.users.currentUser ? store.state.instance.redirectRootLogin - : store.state.instance.redirectRootNoLogin) || '/~/main/all' + : store.state.instance.redirectRootNoLogin) || '/main/all' } }, - { name: 'public-external-timeline', path: '/~/main/all', component: PublicAndExternalTimeline }, - { name: 'public-timeline', path: '/~/main/public', component: PublicTimeline }, - { name: 'friends', path: '/~/main/friends', component: FriendsTimeline }, - // Beginning of temporary redirects - { path: '/main/:route', - redirect: to => { - const { params } = to - const route = params.route ? params.route : 'all' - - return { path: `/~/main/${route}` } - } - }, - { path: '/tag/:tag', - redirect: to => { - const { params } = to - - return { path: `/~/tag/${params.tag}` } - } - }, - { path: '/notice/:id', - redirect: to => { - const { params } = to - - return { path: `/~/notice/${params.id}` } - } - }, - // End of temporary redirects - { name: 'tag-timeline', path: '/~/tag/:tag', component: TagTimeline }, - { name: 'conversation', path: '/~/notice/:id', component: ConversationPage, meta: { dontScroll: true } }, - { name: 'user-profile', path: '/:name', component: UserProfile }, - { name: 'external-user-profile', path: '/~/users/:id', component: UserProfile }, - { name: 'mentions', path: '/:username/mentions', component: Mentions }, - { name: 'dms', path: '/:username/dms', component: DMs }, - { name: 'settings', path: '/~/settings', component: Settings }, - { name: 'registration', path: '/~/registration', component: Registration }, - { name: 'registration', path: '/~/registration/:token', component: Registration }, - { name: 'friend-requests', path: '/~/friend-requests', component: FollowRequests }, - { name: 'user-settings', path: '/~/user-settings', component: UserSettings }, - { name: 'oauth-callback', path: '/~/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) }, - { name: 'user-search', path: '/~/user-search', component: UserSearch, props: (route) => ({ query: route.query.query }) } + { name: 'public-external-timeline', path: '/main/all', component: PublicAndExternalTimeline }, + { name: 'public-timeline', path: '/main/public', component: PublicTimeline }, + { name: 'friends', path: '/main/friends', component: FriendsTimeline }, + { name: 'tag-timeline', path: '/tag/:tag', component: TagTimeline }, + { name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } }, + { name: 'external-user-profile', path: '/users/:id', component: UserProfile }, + { name: 'mentions', path: '/users/:username/mentions', component: Mentions }, + { name: 'dms', path: '/users/:username/dms', component: DMs }, + { name: 'settings', path: '/settings', component: Settings }, + { name: 'registration', path: '/registration', component: Registration }, + { name: 'registration', path: '/registration/:token', component: Registration }, + { name: 'friend-requests', path: '/friend-requests', component: FollowRequests }, + { name: 'user-settings', path: '/user-settings', component: UserSettings }, + { name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) }, + { name: 'user-search', path: '/user-search', component: UserSearch, props: (route) => ({ query: route.query.query }) }, + { name: 'user-profile', path: '/(users/)?:name', component: UserProfile } ] } diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index 81426b44..013222a8 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -32,7 +32,7 @@ const LoginForm = { .then((result) => { this.$store.commit('setToken', result.access_token) this.$store.dispatch('loginUser', result.access_token) - this.$router.push('/~/main/friends') + this.$router.push({name: 'friends'}) }) }) } diff --git a/src/components/oauth_callback/oauth_callback.js b/src/components/oauth_callback/oauth_callback.js index 18e24159..e3d45ee1 100644 --- a/src/components/oauth_callback/oauth_callback.js +++ b/src/components/oauth_callback/oauth_callback.js @@ -11,7 +11,7 @@ const oac = { }).then((result) => { this.$store.commit('setToken', result.access_token) this.$store.dispatch('loginUser', result.access_token) - this.$router.push('/~/main/friends') + this.$router.push({name: 'friends'}) }) } } diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js index dd8e6e5d..ab6cd64d 100644 --- a/src/components/registration/registration.js +++ b/src/components/registration/registration.js @@ -28,7 +28,7 @@ const registration = { }, created () { if ((!this.registrationOpen && !this.token) || this.signedIn) { - this.$router.push('/~/main/all') + this.$router.push({name: 'root'}) } this.setCaptcha() @@ -58,7 +58,7 @@ const registration = { if (!this.$v.$invalid) { try { await this.signUp(this.user) - this.$router.push('/~/main/friends') + this.$router.push({name: 'friends'}) } catch (error) { console.warn('Registration failed: ' + error) } diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index d5fac17d..dcce275a 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -257,7 +257,7 @@ const UserSettings = { .then((res) => { if (res.status === 'success') { this.$store.dispatch('logout') - this.$router.push('/~/main/all') + this.$router.push({name: 'root'}) } else { this.deleteAccountError = res.error } diff --git a/src/modules/instance.js b/src/modules/instance.js index 342bc9ac..ab88306f 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -12,8 +12,8 @@ const defaultState = { logo: '/static/logo.png', logoMask: true, logoMargin: '.2em', - redirectRootNoLogin: '/~/main/all', - redirectRootLogin: '/~/main/friends', + redirectRootNoLogin: '/main/all', + redirectRootLogin: '/main/friends', showInstanceSpecificPanel: false, scopeOptionsEnabled: true, formattingOptionsEnabled: false, diff --git a/src/services/new_api/oauth.js b/src/services/new_api/oauth.js index 97dec94f..9e656507 100644 --- a/src/services/new_api/oauth.js +++ b/src/services/new_api/oauth.js @@ -5,7 +5,7 @@ const getOrCreateApp = ({oauth, instance}) => { const form = new window.FormData() form.append('client_name', `PleromaFE_${Math.random()}`) - form.append('redirect_uris', `${window.location.origin}/~/oauth-callback`) + form.append('redirect_uris', `${window.location.origin}/oauth-callback`) form.append('scopes', 'read write follow') return window.fetch(url, { @@ -64,7 +64,7 @@ const getToken = ({app, instance, code}) => { form.append('client_secret', app.client_secret) form.append('grant_type', 'authorization_code') form.append('code', code) - form.append('redirect_uri', `${window.location.origin}/~/oauth-callback`) + form.append('redirect_uri', `${window.location.origin}/oauth-callback`) return window.fetch(url, { method: 'POST', diff --git a/static/config.json b/static/config.json index f508eea1..7c62eafa 100644 --- a/static/config.json +++ b/static/config.json @@ -4,8 +4,8 @@ "logo": "/static/logo.png", "logoMask": true, "logoMargin": ".1em", - "redirectRootNoLogin": "/~/main/all", - "redirectRootLogin": "/~/main/friends", + "redirectRootNoLogin": "/main/all", + "redirectRootLogin": "/main/friends", "chatDisabled": false, "showInstanceSpecificPanel": false, "scopeOptionsEnabled": false, diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js index 9963555f..383ba90f 100644 --- a/test/unit/specs/boot/routes.spec.js +++ b/test/unit/specs/boot/routes.spec.js @@ -12,7 +12,7 @@ describe('routes', () => { }) it('root path', () => { - router.push('/~/main/all') + router.push('/main/all') const matchedComponents = router.getMatchedComponents() @@ -26,4 +26,12 @@ describe('routes', () => { expect(matchedComponents[0].components.hasOwnProperty('UserCardContent')).to.eql(true) }) + + it('user\'s profile at /users', () => { + router.push('/users/fake-user-name') + + const matchedComponents = router.getMatchedComponents() + + expect(matchedComponents[0].components.hasOwnProperty('UserCardContent')).to.eql(true) + }) }) From f35dbaf064cfe14ee26053a729ae1c31b76800e2 Mon Sep 17 00:00:00 2001 From: Lambda Date: Wed, 26 Dec 2018 14:50:48 +0100 Subject: [PATCH 2/2] Treat reserved users like external users in the frontend. --- src/boot/after_store.js | 2 ++ src/components/chat_panel/chat_panel.js | 2 +- src/components/notification/notification.js | 2 +- src/components/status/status.js | 2 +- src/components/user_card/user_card.js | 2 +- src/components/user_card_content/user_card_content.js | 2 +- .../who_to_follow_panel/who_to_follow_panel.js | 2 +- src/modules/instance.js | 1 + .../user_profile_link_generator.js | 9 ++++++--- .../user_profile_link_generator.spec.js | 6 ++++++ 10 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 5b9e5c96..e716082a 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -165,6 +165,8 @@ const afterStoreSetup = ({ store, i18n }) => { store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') }) store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) + store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames }) + const suggestions = metadata.suggestions store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) store.dispatch('setInstanceOption', { name: 'suggestionsWeb', value: suggestions.web }) diff --git a/src/components/chat_panel/chat_panel.js b/src/components/chat_panel/chat_panel.js index e175e90c..8db12abb 100644 --- a/src/components/chat_panel/chat_panel.js +++ b/src/components/chat_panel/chat_panel.js @@ -22,7 +22,7 @@ const chatPanel = { this.collapsed = !this.collapsed }, userProfileLink (user) { - return generateProfileLink(user.id, user.screen_name) + return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) } } } diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 9ab870b6..e83b2263 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -23,7 +23,7 @@ const Notification = { this.userExpanded = !this.userExpanded }, userProfileLink (user) { - return generateProfileLink(user.id, user.screen_name) + return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) } }, computed: { diff --git a/src/components/status/status.js b/src/components/status/status.js index e683056f..d4eb0d60 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -291,7 +291,7 @@ const Status = { this.showPreview = false }, userProfileLink (id, name) { - return generateProfileLink(id, name) + return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames) } }, watch: { diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index f0fff335..615e6487 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -33,7 +33,7 @@ const UserCard = { this.$store.dispatch('removeFollowRequest', this.user) }, userProfileLink (user) { - return generateProfileLink(user.id, user.screen_name) + return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) } } } diff --git a/src/components/user_card_content/user_card_content.js b/src/components/user_card_content/user_card_content.js index 75185053..6d9b3c2f 100644 --- a/src/components/user_card_content/user_card_content.js +++ b/src/components/user_card_content/user_card_content.js @@ -180,7 +180,7 @@ export default { } }, userProfileLink (user) { - return generateProfileLink(user.id, user.screen_name) + return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) } } } diff --git a/src/components/who_to_follow_panel/who_to_follow_panel.js b/src/components/who_to_follow_panel/who_to_follow_panel.js index b2183e6d..eaeb527a 100644 --- a/src/components/who_to_follow_panel/who_to_follow_panel.js +++ b/src/components/who_to_follow_panel/who_to_follow_panel.js @@ -62,7 +62,7 @@ const WhoToFollowPanel = { }, methods: { userProfileLink (id, name) { - return generateProfileLink(id, name) + return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames) } }, watch: { diff --git a/src/modules/instance.js b/src/modules/instance.js index ab88306f..093bfd0f 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -32,6 +32,7 @@ const defaultState = { pleromaBackend: true, emoji: [], customEmoji: [], + restrictedNicknames: [], // Feature-set, apparently, not everything here is reported... mediaProxyAvailable: false, diff --git a/src/services/user_profile_link_generator/user_profile_link_generator.js b/src/services/user_profile_link_generator/user_profile_link_generator.js index 3367eb8a..bca2c9cd 100644 --- a/src/services/user_profile_link_generator/user_profile_link_generator.js +++ b/src/services/user_profile_link_generator/user_profile_link_generator.js @@ -1,7 +1,10 @@ -const generateProfileLink = (id, screenName) => { +import { includes } from 'lodash' + +const generateProfileLink = (id, screenName, restrictedNicknames) => { + const complicated = (isExternal(screenName) || includes(restrictedNicknames, screenName)) return { - name: (isExternal(screenName) ? 'external-user-profile' : 'user-profile'), - params: (isExternal(screenName) ? { id } : { name: screenName }) + name: (complicated ? 'external-user-profile' : 'user-profile'), + params: (complicated ? { id } : { name: screenName }) } } diff --git a/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js b/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js index 4366f799..8c7a2895 100644 --- a/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js +++ b/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js @@ -12,4 +12,10 @@ describe('generateProfileLink', () => { name: 'external-user-profile', params: { id: 1 } }) }) + + it('returns obj for restricted user', () => { + expect(generateProfileLink(1, 'lain', ['lain'])).to.eql({ + name: 'external-user-profile', params: { id: 1 } + }) + }) })