From 4bc8fbf714fcb5a84fac27ff932c19f20de34025 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 4 Oct 2019 18:28:25 +0200 Subject: [PATCH 1/2] Redirect to profile creation when user has no identities Also load persons by ID instead of preferred_username Signed-off-by: Thomas Citharel --- js/src/App.vue | 7 +- js/src/components/NavBar.vue | 9 ++ js/src/graphql/actor.ts | 42 ++++- js/src/graphql/event.ts | 23 ++- js/src/views/Account/Profile.vue | 2 +- js/src/views/Account/Register.vue | 42 ++--- .../views/Account/children/EditIdentity.vue | 10 +- js/src/views/Event/Edit.vue | 144 ++++++++---------- js/src/views/Event/Event.vue | 7 +- js/src/views/User/Register.vue | 2 +- js/src/views/User/Validate.vue | 7 +- lib/mobilizon_web/resolvers/person.ex | 30 +++- lib/mobilizon_web/schema/actors/person.ex | 16 +- schema.graphql | 13 +- .../resolvers/person_resolver_test.exs | 85 ++++++++--- 15 files changed, 269 insertions(+), 170 deletions(-) diff --git a/js/src/App.vue b/js/src/App.vue index b7942af3a..45a8cb599 100644 --- a/js/src/App.vue +++ b/js/src/App.vue @@ -13,19 +13,14 @@ import NavBar from '@/components/NavBar.vue'; import { Component, Vue } from 'vue-property-decorator'; import { AUTH_ACCESS_TOKEN, - AUTH_USER_ACTOR_ID, AUTH_USER_EMAIL, AUTH_USER_ID, AUTH_USER_ROLE, } from '@/constants'; import { CURRENT_USER_CLIENT, UPDATE_CURRENT_USER_CLIENT } from '@/graphql/user'; -import { ICurrentUser } from '@/types/current-user.model'; import Footer from '@/components/Footer.vue'; import Logo from '@/components/Logo.vue'; -import { CURRENT_ACTOR_CLIENT, IDENTITIES, UPDATE_CURRENT_ACTOR_CLIENT } from '@/graphql/actor'; -import { IPerson } from '@/types/actor'; -import { changeIdentity, initializeCurrentActor, saveActorData } from '@/utils/auth'; - +import { initializeCurrentActor } from '@/utils/auth'; @Component({ apollo: { currentUser: { diff --git a/js/src/components/NavBar.vue b/js/src/components/NavBar.vue index 27425aa2d..071cec7b7 100644 --- a/js/src/components/NavBar.vue +++ b/js/src/components/NavBar.vue @@ -119,6 +119,15 @@ export default class NavBar extends Vue { }); if (data) { this.identities = data.identities.map(identity => new Person(identity)); + + // If we don't have any identities, the user has validated their account, + // is logging for the first time but didn't create an identity somehow + if (this.identities.length === 0) { + await this.$router.push({ + name: RouteName.REGISTER_PROFILE, + params: { email: this.currentUser.email, userAlreadyActivated: 'true' }, + }); + } } } diff --git a/js/src/graphql/actor.ts b/js/src/graphql/actor.ts index d8edd45f3..ec7d36d3b 100644 --- a/js/src/graphql/actor.ts +++ b/js/src/graphql/actor.ts @@ -1,8 +1,8 @@ import gql from 'graphql-tag'; export const FETCH_PERSON = gql` -query($name:String!) { - person(preferredUsername: $name) { +query($username: String!) { + fetchPerson(preferredUsername: $username) { id, url, name, @@ -29,6 +29,35 @@ query($name:String!) { } `; +export const GET_PERSON = gql` + query($actorId: ID!) { + person(id: $actorId) { + id, + url, + name, + domain, + summary, + preferredUsername, + suspended, + avatar { + name, + url + }, + banner { + url + }, + feedTokens { + token + }, + organizedEvents { + uuid, + title, + beginsOn + }, + } + } +`; + export const LOGGED_PERSON = gql` query { loggedPerson { @@ -172,9 +201,9 @@ mutation CreatePerson($preferredUsername: String!, $name: String!, $summary: Str `; export const UPDATE_PERSON = gql` - mutation UpdatePerson($preferredUsername: String!, $name: String, $summary: String, $avatar: PictureInput) { + mutation UpdatePerson($id: ID!, $name: String, $summary: String, $avatar: PictureInput) { updatePerson( - preferredUsername: $preferredUsername, + id: $id, name: $name, summary: $summary, avatar: $avatar @@ -191,8 +220,8 @@ export const UPDATE_PERSON = gql` `; export const DELETE_PERSON = gql` - mutation DeletePerson($preferredUsername: String!) { - deletePerson(preferredUsername: $preferredUsername) { + mutation DeletePerson($id: ID!) { + deletePerson(id: $id) { preferredUsername, } } @@ -209,6 +238,7 @@ mutation ($preferredUsername: String!, $name: String!, $summary: String!, $email summary: $summary, email: $email ) { + id, preferredUsername, name, summary, diff --git a/js/src/graphql/event.ts b/js/src/graphql/event.ts index a3a7cd5e9..7d1fbefcc 100644 --- a/js/src/graphql/event.ts +++ b/js/src/graphql/event.ts @@ -221,6 +221,8 @@ export const CREATE_EVENT = gql` id, uuid, title, + url, + local, description, beginsOn, endsOn, @@ -239,14 +241,25 @@ export const CREATE_EVENT = gql` physicalAddress { ${physicalAddressQuery} }, + organizerActor { + avatar { + url + }, + preferredUsername, + domain, + name, + url, + id, + }, + participantStats { + approved, + unapproved + }, tags { ${tagsQuery} }, options { ${optionsQuery} - }, - organizerActor { - id } } } @@ -397,8 +410,8 @@ export const PARTICIPANTS = gql` `; export const EVENT_PERSON_PARTICIPATION = gql` - query($name: String!, $eventId: ID!) { - person(preferredUsername: $name) { + query($actorId: ID!, $eventId: ID!) { + person(id: $actorId) { id, participations(eventId: $eventId) { id, diff --git a/js/src/views/Account/Profile.vue b/js/src/views/Account/Profile.vue index 1faff09c2..c414b647c 100644 --- a/js/src/views/Account/Profile.vue +++ b/js/src/views/Account/Profile.vue @@ -104,7 +104,7 @@ import { CREATE_FEED_TOKEN_ACTOR } from '@/graphql/feed_tokens'; query: FETCH_PERSON, variables() { return { - name: this.$route.params.name, + username: this.$route.params.name, }; }, }, diff --git a/js/src/views/Account/Register.vue b/js/src/views/Account/Register.vue index 07236d154..0fa72dd87 100644 --- a/js/src/views/Account/Register.vue +++ b/js/src/views/Account/Register.vue @@ -69,10 +69,12 @@