Browse Source

Feature: Mobile - Add query and subscription for public links.

Florian Liebe 2 years ago
parent
commit
46d360f26e

+ 22 - 0
app/frontend/shared/entities/public-links/graphql/queries/links.api.ts

@@ -0,0 +1,22 @@
+import * as Types from '../../../../graphql/types';
+
+import gql from 'graphql-tag';
+import { PublicLinkAttributesFragmentDoc } from '../../../../graphql/fragments/publicLinkAttributes.api';
+import * as VueApolloComposable from '@vue/apollo-composable';
+import * as VueCompositionApi from 'vue';
+export type ReactiveFunction<TParam> = () => TParam;
+
+export const PublicLinksDocument = gql`
+    query publicLinks($screen: EnumPublicLinksScreen!) {
+  publicLinks(screen: $screen) {
+    ...publicLinkAttributes
+  }
+}
+    ${PublicLinkAttributesFragmentDoc}`;
+export function usePublicLinksQuery(variables: Types.PublicLinksQueryVariables | VueCompositionApi.Ref<Types.PublicLinksQueryVariables> | ReactiveFunction<Types.PublicLinksQueryVariables>, options: VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables> | VueCompositionApi.Ref<VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>> | ReactiveFunction<VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>> = {}) {
+  return VueApolloComposable.useQuery<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>(PublicLinksDocument, variables, options);
+}
+export function usePublicLinksLazyQuery(variables: Types.PublicLinksQueryVariables | VueCompositionApi.Ref<Types.PublicLinksQueryVariables> | ReactiveFunction<Types.PublicLinksQueryVariables>, options: VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables> | VueCompositionApi.Ref<VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>> | ReactiveFunction<VueApolloComposable.UseQueryOptions<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>> = {}) {
+  return VueApolloComposable.useLazyQuery<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>(PublicLinksDocument, variables, options);
+}
+export type PublicLinksQueryCompositionFunctionResult = VueApolloComposable.UseQueryReturn<Types.PublicLinksQuery, Types.PublicLinksQueryVariables>;

+ 5 - 0
app/frontend/shared/entities/public-links/graphql/queries/links.graphql

@@ -0,0 +1,5 @@
+query publicLinks($screen: EnumPublicLinksScreen!) {
+  publicLinks(screen: $screen) {
+    ...publicLinkAttributes
+  }
+}

+ 21 - 0
app/frontend/shared/entities/public-links/graphql/subscriptions/currentLinks.api.ts

@@ -0,0 +1,21 @@
+import * as Types from '../../../../graphql/types';
+
+import gql from 'graphql-tag';
+import { PublicLinkAttributesFragmentDoc } from '../../../../graphql/fragments/publicLinkAttributes.api';
+import * as VueApolloComposable from '@vue/apollo-composable';
+import * as VueCompositionApi from 'vue';
+export type ReactiveFunction<TParam> = () => TParam;
+
+export const PublicLinkUpdatesDocument = gql`
+    subscription publicLinkUpdates($screen: EnumPublicLinksScreen!) {
+  publicLinkUpdates(screen: $screen) {
+    publicLinks {
+      ...publicLinkAttributes
+    }
+  }
+}
+    ${PublicLinkAttributesFragmentDoc}`;
+export function usePublicLinkUpdatesSubscription(variables: Types.PublicLinkUpdatesSubscriptionVariables | VueCompositionApi.Ref<Types.PublicLinkUpdatesSubscriptionVariables> | ReactiveFunction<Types.PublicLinkUpdatesSubscriptionVariables>, options: VueApolloComposable.UseSubscriptionOptions<Types.PublicLinkUpdatesSubscription, Types.PublicLinkUpdatesSubscriptionVariables> | VueCompositionApi.Ref<VueApolloComposable.UseSubscriptionOptions<Types.PublicLinkUpdatesSubscription, Types.PublicLinkUpdatesSubscriptionVariables>> | ReactiveFunction<VueApolloComposable.UseSubscriptionOptions<Types.PublicLinkUpdatesSubscription, Types.PublicLinkUpdatesSubscriptionVariables>> = {}) {
+  return VueApolloComposable.useSubscription<Types.PublicLinkUpdatesSubscription, Types.PublicLinkUpdatesSubscriptionVariables>(PublicLinkUpdatesDocument, variables, options);
+}
+export type PublicLinkUpdatesSubscriptionCompositionFunctionResult = VueApolloComposable.UseSubscriptionReturn<Types.PublicLinkUpdatesSubscription, Types.PublicLinkUpdatesSubscriptionVariables>;

+ 7 - 0
app/frontend/shared/entities/public-links/graphql/subscriptions/currentLinks.graphql

@@ -0,0 +1,7 @@
+subscription publicLinkUpdates($screen: EnumPublicLinksScreen!) {
+  publicLinkUpdates(screen: $screen) {
+    publicLinks {
+      ...publicLinkAttributes
+    }
+  }
+}

+ 12 - 0
app/frontend/shared/graphql/fragments/publicLinkAttributes.api.ts

@@ -0,0 +1,12 @@
+import * as Types from '../types';
+
+import gql from 'graphql-tag';
+export const PublicLinkAttributesFragmentDoc = gql`
+    fragment publicLinkAttributes on PublicLink {
+  id
+  link
+  title
+  description
+  newTab
+}
+    `;

+ 7 - 0
app/frontend/shared/graphql/fragments/publicLinkAttributes.graphql

@@ -0,0 +1,7 @@
+fragment publicLinkAttributes on PublicLink {
+  id
+  link
+  title
+  description
+  newTab
+}

+ 64 - 0
app/frontend/shared/graphql/types.ts

@@ -172,6 +172,13 @@ export enum EnumOrderDirection {
   Descending = 'DESCENDING'
 }
 
+/** All available public links screens */
+export enum EnumPublicLinksScreen {
+  Login = 'login',
+  PasswordReset = 'password_reset',
+  Signup = 'signup'
+}
+
 /** All searchable models */
 export enum EnumSearchableModels {
   Organization = 'Organization',
@@ -704,6 +711,31 @@ export type PageInfo = {
   startCursor?: Maybe<Scalars['String']>;
 };
 
+/** Public links available in the system */
+export type PublicLink = {
+  __typename?: 'PublicLink';
+  /** Create date/time of the record */
+  createdAt: Scalars['ISO8601DateTime'];
+  /** User that created this record */
+  createdBy: User;
+  description?: Maybe<Scalars['String']>;
+  id: Scalars['ID'];
+  link: Scalars['String'];
+  newTab: Scalars['Boolean'];
+  title: Scalars['String'];
+  /** Last update date/time of the record */
+  updatedAt: Scalars['ISO8601DateTime'];
+  /** Last user that updated this record */
+  updatedBy: User;
+};
+
+/** Autogenerated return type of PublicLinkUpdates */
+export type PublicLinkUpdatesPayload = {
+  __typename?: 'PublicLinkUpdatesPayload';
+  /** Current available public links */
+  publicLinks?: Maybe<Array<PublicLink>>;
+};
+
 /** Autogenerated return type of PushMessages */
 export type PushMessagesPayload = {
   __typename?: 'PushMessagesPayload';
@@ -740,6 +772,8 @@ export type Queries = {
   organization: Organization;
   /** Fetch the version of Zammad */
   productAbout: Scalars['String'];
+  /** Fetch public links */
+  publicLinks?: Maybe<Array<PublicLink>>;
   /** Generic object search */
   search: Array<SearchResult>;
   /** The sessionId of the currently authenticated user. */
@@ -810,6 +844,12 @@ export type QueriesOrganizationArgs = {
 };
 
 
+/** All available queries */
+export type QueriesPublicLinksArgs = {
+  screen: EnumPublicLinksScreen;
+};
+
+
 /** All available queries */
 export type QueriesSearchArgs = {
   limit?: InputMaybe<Scalars['Int']>;
@@ -920,6 +960,8 @@ export type Subscriptions = {
   onlineNotificationsCount: OnlineNotificationsCountPayload;
   /** Updates to organization records */
   organizationUpdates: OrganizationUpdatesPayload;
+  /** Updates to public links */
+  publicLinkUpdates: PublicLinkUpdatesPayload;
   /** Broadcast messages to all users */
   pushMessages: PushMessagesPayload;
   /** Updates to ticket records */
@@ -941,6 +983,12 @@ export type SubscriptionsOrganizationUpdatesArgs = {
 };
 
 
+/** All available subscriptions */
+export type SubscriptionsPublicLinkUpdatesArgs = {
+  screen: EnumPublicLinksScreen;
+};
+
+
 /** All available subscriptions */
 export type SubscriptionsTicketUpdatesArgs = {
   ticketId: Scalars['ID'];
@@ -1525,6 +1573,20 @@ export type OnlineNotificationsCountSubscriptionVariables = Exact<{
 
 export type OnlineNotificationsCountSubscription = { __typename?: 'Subscriptions', onlineNotificationsCount: { __typename?: 'OnlineNotificationsCountPayload', unseenCount: number } };
 
+export type PublicLinksQueryVariables = Exact<{
+  screen: EnumPublicLinksScreen;
+}>;
+
+
+export type PublicLinksQuery = { __typename?: 'Queries', publicLinks?: Array<{ __typename?: 'PublicLink', id: string, link: string, title: string, description?: string | null, newTab: boolean }> | null };
+
+export type PublicLinkUpdatesSubscriptionVariables = Exact<{
+  screen: EnumPublicLinksScreen;
+}>;
+
+
+export type PublicLinkUpdatesSubscription = { __typename?: 'Subscriptions', publicLinkUpdates: { __typename?: 'PublicLinkUpdatesPayload', publicLinks?: Array<{ __typename?: 'PublicLink', id: string, link: string, title: string, description?: string | null, newTab: boolean }> | null } };
+
 export type TicketOverviewsQueryVariables = Exact<{
   withTicketCount: Scalars['Boolean'];
 }>;
@@ -1538,6 +1600,8 @@ export type ErrorsFragment = { __typename?: 'UserError', message: string, field?
 
 export type ObjectAttributeValuesFragment = { __typename?: 'ObjectAttributeValue', value?: any | null, attribute: { __typename?: 'ObjectManagerFrontendAttribute', name: string, display: string, dataType: string, dataOption?: any | null } };
 
+export type PublicLinkAttributesFragment = { __typename?: 'PublicLink', id: string, link: string, title: string, description?: string | null, newTab: boolean };
+
 export type UserAttributesFragment = { __typename?: 'User', id: string, firstname?: string | null, lastname?: string | null, fullname?: string | null, image?: string | null, preferences?: any | null, objectAttributeValues?: Array<{ __typename?: 'ObjectAttributeValue', value?: any | null, attribute: { __typename?: 'ObjectManagerFrontendAttribute', name: string, display: string, dataType: string, dataOption?: any | null } }> | null, organization?: { __typename?: 'Organization', name?: string | null, objectAttributeValues?: Array<{ __typename?: 'ObjectAttributeValue', value?: any | null, attribute: { __typename?: 'ObjectManagerFrontendAttribute', name: string, display: string, dataType: string, dataOption?: any | null } }> | null } | null };
 
 export type UserDetailAttributesFragment = { __typename?: 'User', id: string, internalId: number, firstname?: string | null, lastname?: string | null, fullname?: string | null, image?: string | null, email?: string | null, web?: string | null, vip?: boolean | null, phone?: string | null, mobile?: string | null, fax?: string | null, note?: string | null, objectAttributeValues?: Array<{ __typename?: 'ObjectAttributeValue', value?: any | null, attribute: { __typename?: 'ObjectManagerFrontendAttribute', name: string, display: string, dataType: string, dataOption?: any | null } }> | null, organization?: { __typename?: 'Organization', id: string, internalId: number, name?: string | null, ticketsCount?: { __typename?: 'TicketCount', open: number, closed: number } | null } | null, ticketsCount?: { __typename?: 'TicketCount', open: number, closed: number } | null };

+ 20 - 0
app/graphql/gql/queries/public_links.rb

@@ -0,0 +1,20 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+module Gql::Queries
+  class PublicLinks < BaseQuery
+    description 'Fetch public links'
+
+    argument :screen, Gql::Types::Enum::PublicLinksScreenType, required: true, description: 'Fetch public links for a specific screen'
+
+    type [Gql::Types::PublicLinkType], null: true
+
+    # This query is available for all (including unauthenticated) users.
+    def self.authorize(...)
+      true
+    end
+
+    def resolve(screen:)
+      PublicLink.all.select { |link| link[:screen].include?(screen) }
+    end
+  end
+end

+ 20 - 0
app/graphql/gql/subscriptions/public_link_updates.rb

@@ -0,0 +1,20 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+module Gql::Subscriptions
+  class PublicLinkUpdates < BaseSubscription
+
+    description 'Updates to public links'
+
+    argument :screen, Gql::Types::Enum::PublicLinksScreenType, required: true, description: 'Subscribe to public links for a specific screen'
+
+    field :public_links, [Gql::Types::PublicLinkType], description: 'Current available public links'
+
+    def self.authorize(...)
+      true # This subscription should be available for all (including unauthenticated) users.
+    end
+
+    def update(screen:)
+      { public_links: PublicLink.all.select { |link| link[:screen].include?(screen) } }
+    end
+  end
+end

+ 9 - 0
app/graphql/gql/types/enum/public_links_screen_type.rb

@@ -0,0 +1,9 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+module Gql::Types::Enum
+  class PublicLinksScreenType < BaseEnum
+    description 'All available public links screens'
+
+    build_string_list_enum PublicLink::AVAILABLE_SCREENS
+  end
+end

Some files were not shown because too many files changed in this diff