From 39924292363f9fa6a5a0fc67f485a70b59e891b0 Mon Sep 17 00:00:00 2001 From: Dominik Korsa Date: Fri, 22 Jan 2021 20:31:58 +0100 Subject: [PATCH] Add app info dialog --- backend/package-lock.json | 23 ++++ backend/package.json | 2 + backend/src/database/entities/application.ts | 6 + .../src/graphql/github/queries/get-user.ts | 20 +++ backend/src/graphql/github/sdk.ts | 14 ++ .../routes/website-api/models/github-user.ts | 15 +++ .../models/prompt-info-application.ts | 9 ++ .../resolvers/prompt-info-resolver.ts | 3 + .../app-info-dialog.vue | 122 ++++++++++++++++++ .../overview-window.vue | 4 +- website/src/compontents/dialog-app.vue | 4 + website/src/graphql/generated.ts | 21 ++- .../src/graphql/queries/get-prompt-info.ts | 6 + website/src/pages/authenticate-prompt/app.vue | 2 +- website/src/types.ts | 6 + 15 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 backend/src/graphql/github/queries/get-user.ts create mode 100644 backend/src/graphql/github/sdk.ts create mode 100644 backend/src/routes/website-api/models/github-user.ts create mode 100644 website/src/compontents/authenticate-prompt-windows/app-info-dialog.vue diff --git a/backend/package-lock.json b/backend/package-lock.json index 3e5a15a..438a07b 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1412,6 +1412,14 @@ "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" }, + "cross-fetch": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz", + "integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==", + "requires": { + "node-fetch": "2.6.1" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -2056,6 +2064,11 @@ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz", "integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==" }, + "extract-files": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/extract-files/-/extract-files-9.0.0.tgz", + "integrity": "sha512-CvdFfHkC95B4bBBk36hcEmvdR2awOdhhVUYH6S/zrVj3477zven/fJMYg7121h4T1xHZC+tetUpubpAhxwI7hQ==" + }, "fast-decode-uri-component": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz", @@ -2484,6 +2497,16 @@ "lodash.get": "^4.4.2" } }, + "graphql-request": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-3.4.0.tgz", + "integrity": "sha512-acrTzidSlwAj8wBNO7Q/UQHS8T+z5qRGquCQRv9J1InwR01BBWV9ObnoE+JS5nCCEj8wSGS0yrDXVDoRiKZuOg==", + "requires": { + "cross-fetch": "^3.0.6", + "extract-files": "^9.0.0", + "form-data": "^3.0.0" + } + }, "graphql-subscriptions": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-1.1.0.tgz", diff --git a/backend/package.json b/backend/package.json index 0822b62..b57d9fd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -27,6 +27,8 @@ "fastify-sensible": "^3.1.0", "fastify-session": "^5.2.1", "got": "^11.8.1", + "graphql-request": "^3.4.0", + "graphql-tag": "^2.11.0", "lodash": "^4.17.20", "mongodb": "^3.6.3", "nanoid": "^3.1.20", diff --git a/backend/src/database/entities/application.ts b/backend/src/database/entities/application.ts index 4512784..40bdb48 100644 --- a/backend/src/database/entities/application.ts +++ b/backend/src/database/entities/application.ts @@ -28,6 +28,12 @@ export default class Application extends BaseEntity { @Column() public redirectUris!: string[]; + @Column() + public ownerGitHubLogin!: string; + + @Column() + public homepage!: string | null; + public static generateClientId(): string { return nanoid(12); } diff --git a/backend/src/graphql/github/queries/get-user.ts b/backend/src/graphql/github/queries/get-user.ts new file mode 100644 index 0000000..ffc0fc0 --- /dev/null +++ b/backend/src/graphql/github/queries/get-user.ts @@ -0,0 +1,20 @@ +import gql from 'graphql-tag'; + +export const getUserQuery = gql`query GetUser($login: String!) { + user(login: $login) { + login + name + url + } +} +`; + +export interface User { + login: string; + name: string | null; + url: string; +} + +export interface GetUserQueryResult { + user: User +} diff --git a/backend/src/graphql/github/sdk.ts b/backend/src/graphql/github/sdk.ts new file mode 100644 index 0000000..6e1db65 --- /dev/null +++ b/backend/src/graphql/github/sdk.ts @@ -0,0 +1,14 @@ +import { GraphQLClient } from 'graphql-request'; +import { requireEnv } from '../../utils'; +import type { GetUserQueryResult, User } from './queries/get-user'; +import { getUserQuery } from './queries/get-user'; + +const client = new GraphQLClient('https://api.github.com/graphql'); +client.setHeader('Authorization', `bearer ${requireEnv('GITHUB_API_TOKEN')}`); + +export async function getUser(login: string): Promise { + const { user } = await client.request(getUserQuery, { + login, + }); + return user; +} diff --git a/backend/src/routes/website-api/models/github-user.ts b/backend/src/routes/website-api/models/github-user.ts new file mode 100644 index 0000000..79ff6e3 --- /dev/null +++ b/backend/src/routes/website-api/models/github-user.ts @@ -0,0 +1,15 @@ +import { Field, ObjectType } from 'type-graphql'; + +@ObjectType() +export default class GitHubUser { + @Field(() => String) + public login!: string; + + @Field(() => String, { + nullable: true, + }) + public name!: string | null; + + @Field(() => String) + public url!: string; +} diff --git a/backend/src/routes/website-api/models/prompt-info-application.ts b/backend/src/routes/website-api/models/prompt-info-application.ts index 4408960..9dd9b08 100644 --- a/backend/src/routes/website-api/models/prompt-info-application.ts +++ b/backend/src/routes/website-api/models/prompt-info-application.ts @@ -1,4 +1,5 @@ import { Field, ObjectType } from 'type-graphql'; +import GitHubUser from './github-user'; @ObjectType() export default class PromptInfoApplication { @@ -15,4 +16,12 @@ export default class PromptInfoApplication { @Field(() => Boolean) public verified!: boolean; + + @Field(() => GitHubUser) + public owner!: GitHubUser; + + @Field(() => String, { + nullable: true, + }) + public homepage!: string | null; } diff --git a/backend/src/routes/website-api/resolvers/prompt-info-resolver.ts b/backend/src/routes/website-api/resolvers/prompt-info-resolver.ts index 8e6f773..9390529 100644 --- a/backend/src/routes/website-api/resolvers/prompt-info-resolver.ts +++ b/backend/src/routes/website-api/resolvers/prompt-info-resolver.ts @@ -4,6 +4,7 @@ import { Arg, Ctx, FieldResolver, Query, Resolver, Root, } from 'type-graphql'; import database from '../../../database/database'; +import { getUser } from '../../../graphql/github/sdk'; import { UnknownPromptError } from '../errors'; import PromptInfo from '../models/prompt-info'; import type PromptInfoApplication from '../models/prompt-info-application'; @@ -39,6 +40,8 @@ export default class PromptInfoResolver implements ResolverInterface iconUrl: application.iconUrl, iconColor: application.iconColor, verified: application.verified, + homepage: application.homepage, + owner: await getUser(application.ownerGitHubLogin), }; } } diff --git a/website/src/compontents/authenticate-prompt-windows/app-info-dialog.vue b/website/src/compontents/authenticate-prompt-windows/app-info-dialog.vue new file mode 100644 index 0000000..c8a2543 --- /dev/null +++ b/website/src/compontents/authenticate-prompt-windows/app-info-dialog.vue @@ -0,0 +1,122 @@ + + + diff --git a/website/src/compontents/authenticate-prompt-windows/overview-window.vue b/website/src/compontents/authenticate-prompt-windows/overview-window.vue index f45bd98..7d5fa6a 100644 --- a/website/src/compontents/authenticate-prompt-windows/overview-window.vue +++ b/website/src/compontents/authenticate-prompt-windows/overview-window.vue @@ -3,7 +3,7 @@

Aplikacja - {{ promptInfo.application.name }} + chce uzyskać dostęp do twojego konta VULCAN UONET+ przez Wulkanowy Bridge

Uprawnienia aplikacji @@ -46,9 +46,11 @@