diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 518ef9f46..fea150338 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -47,13 +47,13 @@ import { UserContact } from '@model/UserContact' import { UserLocationResult } from '@model/UserLocationResult' import { HumHubClient } from '@/apis/humhub/HumHubClient' +import { Account as HumhubAccount } from '@/apis/humhub/model/Account' import { GetUser } from '@/apis/humhub/model/GetUser' import { PostUser } from '@/apis/humhub/model/PostUser' import { subscribe } from '@/apis/KlicktippController' import { encode } from '@/auth/JWT' import { RIGHTS } from '@/auth/RIGHTS' import { CONFIG } from '@/config' -import { PublishNameLogic } from '@/data/PublishName.logic' import { sendAccountActivationEmail, sendAccountMultiRegistrationEmail, @@ -75,7 +75,6 @@ import { EVENT_ADMIN_USER_DELETE, EVENT_ADMIN_USER_UNDELETE, } from '@/event/Events' -import { PublishNameType } from '@/graphql/enum/PublishNameType' import { isValidPassword } from '@/password/EncryptorUtils' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { Context, getUser, getClientTimezoneOffset } from '@/server/context' @@ -821,7 +820,7 @@ export class UserResolver { } @Authorized([RIGHTS.HUMHUB_AUTO_LOGIN]) - @Query(() => String) + @Mutation(() => String) async authenticateHumhubAutoLogin( @Ctx() context: Context, @Arg('project', () => String, { nullable: true }) project?: string | null, @@ -832,19 +831,23 @@ export class UserResolver { if (!humhubClient) { throw new LogError('cannot create humhub client') } - const userNameLogic = new PublishNameLogic(dbUser) - const username = userNameLogic.getUserIdentifier(dbUser.humhubPublishName as PublishNameType) - let humhubUser = await humhubClient.userByUsername(username) - if (!humhubUser) { - humhubUser = await humhubClient.userByEmail(dbUser.emailContact.email) + // should rarely happen, so we don't optimize for parallel processing + if (!dbUser.humhubAllowed && project) { + await ProjectBranding.findOneOrFail({ where: { alias: project } }) + dbUser.humhubAllowed = true + await dbUser.save() } + const humhubUserAccount = new HumhubAccount(dbUser) + const autoLoginUrlPromise = humhubClient.createAutoLoginUrl(humhubUserAccount.username, project) + const humhubUser = await syncHumhub(null, dbUser) if (!humhubUser) { - throw new LogError("user don't exist (any longer) on humhub") + throw new LogError("user don't exist (any longer) on humhub and couldn't be created") } if (humhubUser.account.status !== 1) { throw new LogError('user status is not 1', humhubUser.account.status) } - return await humhubClient.createAutoLoginUrl(humhubUser.account.username, project) + const autoLoginUrl = await autoLoginUrlPromise + return autoLoginUrl } @Authorized([RIGHTS.SEARCH_ADMIN_USERS]) diff --git a/backend/src/graphql/resolver/util/syncHumhub.ts b/backend/src/graphql/resolver/util/syncHumhub.ts index b8becd8a2..90500bbc5 100644 --- a/backend/src/graphql/resolver/util/syncHumhub.ts +++ b/backend/src/graphql/resolver/util/syncHumhub.ts @@ -3,7 +3,9 @@ import { User } from '@entity/User' import { HumHubClient } from '@/apis/humhub/HumHubClient' import { GetUser } from '@/apis/humhub/model/GetUser' import { ExecutedHumhubAction, syncUser } from '@/apis/humhub/syncUser' +import { PublishNameLogic } from '@/data/PublishName.logic' import { UpdateUserInfosArgs } from '@/graphql/arg/UpdateUserInfosArgs' +import { PublishNameType } from '@/graphql/enum/PublishNameType' import { backendLogger as logger } from '@/server/logger' /** @@ -16,7 +18,7 @@ export async function syncHumhub( updateUserInfosArg: UpdateUserInfosArgs | null, user: User, spaceId?: number | null, -): Promise { +): Promise { // check for humhub relevant changes if ( updateUserInfosArg && @@ -36,7 +38,9 @@ export async function syncHumhub( return } logger.debug('retrieve user from humhub') - let humhubUser = await humhubClient.userByUsername(user.alias ?? user.gradidoID) + const userNameLogic = new PublishNameLogic(user) + const username = userNameLogic.getUserIdentifier(user.humhubPublishName as PublishNameType) + let humhubUser = await humhubClient.userByUsername(username) if (!humhubUser) { humhubUser = await humhubClient.userByEmail(user.emailContact.email) } @@ -58,5 +62,8 @@ export async function syncHumhub( await humhubClient.addUserToSpace(humhubUser.id, spaceId) logger.debug(`user added to space ${spaceId}`) } - return user.id + if (result !== ExecutedHumhubAction.SKIP) { + return await humhubClient.userByUsername(username) + } + return humhubUser } diff --git a/frontend/src/components/Overview/CardCircles.vue b/frontend/src/components/Overview/CardCircles.vue index 7452042b5..dc5522448 100644 --- a/frontend/src/components/Overview/CardCircles.vue +++ b/frontend/src/components/Overview/CardCircles.vue @@ -32,10 +32,10 @@