Skip to content

Commit

Permalink
Merge pull request #1728 from serlo/Ptarj-kulla-2024-09-08-19-32
Browse files Browse the repository at this point in the history
refactor(page): Remove unused page mutations
  • Loading branch information
hejtful authored Sep 10, 2024
2 parents 1c64453 + cae4d46 commit bb04d26
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 287 deletions.
29 changes: 0 additions & 29 deletions __tests__/schema/page/add-revision.ts

This file was deleted.

24 changes: 0 additions & 24 deletions __tests__/schema/page/checkout-revision.ts

This file was deleted.

31 changes: 0 additions & 31 deletions __tests__/schema/page/create.ts

This file was deleted.

126 changes: 1 addition & 125 deletions packages/server/src/schema/uuid/page/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import * as serloAuth from '@serlo/authorization'
import { instanceToScope } from '@serlo/authorization'

import { UuidResolver } from '../abstract-uuid/resolvers'
import {
assertStringIsNotEmpty,
assertUserIsAuthenticated,
assertUserIsAuthorized,
createNamespace,
} from '~/internals/graphql'
import { createNamespace } from '~/internals/graphql'
import { PageDecoder, PageRevisionDecoder } from '~/model/decoder'
import { fetchScopeOfUuid } from '~/schema/authorization/utils'
import { resolvers as EntityResolvers } from '~/schema/uuid/abstract-entity/resolvers'
import {
createRepositoryResolvers,
createRevisionResolvers,
Expand All @@ -22,125 +12,11 @@ export const resolvers: Resolvers = {
Query: {
page: createNamespace(),
},
Mutation: {
page: createNamespace(),
},
Page: {
...createRepositoryResolvers({ revisionDecoder: PageRevisionDecoder }),
...createTaxonomyTermChildResolvers(),
},
PageRevision: createRevisionResolvers({ repositoryDecoder: PageDecoder }),
PageMutation: {
async addRevision(_parent, { input }, context, info) {
const { userId } = context
assertUserIsAuthenticated(userId)

const { pageId, content, title } = input

assertStringIsNotEmpty({ content, title })

const scope = await fetchScopeOfUuid({ id: pageId }, context)
await assertUserIsAuthorized({
message: 'You are not allowed to add revision to this page.',
guard: serloAuth.Uuid.create('PageRevision')(scope),
context,
})

const resolver = EntityResolvers.EntityMutation!.setAbstractEntity!

if (typeof resolver !== 'function') {
throw new Error('Resolver is not a function')
}

return resolver(
{},
{
input: {
entityType: 'Page',
changes: 'Page updated',
subscribeThis: false,
subscribeThisByEmail: false,
needsReview: false,
entityId: pageId,
content,
title,
},
},
context,
info,
)
},
async checkoutRevision(_parent, { input }, context, info) {
const { userId } = context
assertUserIsAuthenticated(userId)

const scope = await fetchScopeOfUuid({ id: input.revisionId }, context)

await assertUserIsAuthorized({
message: 'You are not allowed to check out the provided revision.',
guard: serloAuth.Page.checkoutRevision(scope),
context,
})

const resolver = EntityResolvers.EntityMutation!.checkoutRevision!

if (typeof resolver !== 'function') {
throw new Error('Resolver is not a function')
}

return resolver({}, { input }, context, info)
},
async create(_parent, { input }, context, info) {
context.userId = 1
const { userId, database } = context
assertUserIsAuthenticated(userId)

const { content, title, instance } = input

assertStringIsNotEmpty({ content, title })

await assertUserIsAuthorized({
message: 'You are not allowed to create pages.',
guard: serloAuth.Uuid.create('Page')(instanceToScope(instance)),
context,
})

const resolver = EntityResolvers.EntityMutation!.setAbstractEntity!

if (typeof resolver !== 'function') {
throw new Error('Resolver is not a function')
}

const { taxonomyId } = await database.fetchOne<{ taxonomyId: number }>(
`
select
taxonomy.id as taxonomyId
from taxonomy
join instance on taxonomy.instance_id = instance.id
where taxonomy.name = 'Static Pages' and instance.subdomain = ?
`,
[instance],
)

return resolver(
{},
{
input: {
entityType: 'Page',
changes: 'Initial page creation',
subscribeThis: false,
subscribeThisByEmail: false,
needsReview: false,
parentId: taxonomyId,
content,
title,
},
},
context,
info,
)
},
},
PageQuery: {
async pages(_parent, payload, context) {
const pages = await context.database.fetchAll<{ id: number }>(
Expand Down
25 changes: 0 additions & 25 deletions packages/server/src/schema/uuid/page/types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,10 @@ type PageRevisionConnection implements AbstractEntityRevisionConnection {
pageInfo: PageInfo!
}

extend type Mutation {
page: PageMutation!
}

type PageMutation {
addRevision(input: PageAddRevisionInput!): DefaultResponse!
checkoutRevision(input: CheckoutRevisionInput!): DefaultResponse!
create(input: CreatePageInput!): DefaultResponse!
}

extend type Query {
page: PageQuery!
}

type PageQuery {
pages(instance: Instance): [Page!]!
}

input PageAddRevisionInput {
content: String!
pageId: Int!
title: String!
}

input CreatePageInput {
content: String!
discussionsEnabled: Boolean!
instance: Instance!
licenseId: Int!
title: String!
forumId: Int
}
53 changes: 0 additions & 53 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,6 @@ export type CreateEntityRevisionNotificationEvent = AbstractNotificationEvent &
objectId: Scalars['Int']['output'];
};

export type CreatePageInput = {
content: Scalars['String']['input'];
discussionsEnabled: Scalars['Boolean']['input'];
forumId?: InputMaybe<Scalars['Int']['input']>;
instance: Instance;
licenseId: Scalars['Int']['input'];
title: Scalars['String']['input'];
};

export type CreateTaxonomyLinkNotificationEvent = AbstractNotificationEvent & InstanceAware & {
__typename?: 'CreateTaxonomyLinkNotificationEvent';
actor: User;
Expand Down Expand Up @@ -937,7 +928,6 @@ export type Mutation = {
experiment: ExperimentMutation;
notification: NotificationMutation;
oauth: OauthMutation;
page: PageMutation;
subscription: SubscriptionMutation;
taxonomyTerm: TaxonomyTermMutation;
thread: ThreadMutation;
Expand Down Expand Up @@ -1045,40 +1035,12 @@ export type PageThreadsArgs = {
trashed?: InputMaybe<Scalars['Boolean']['input']>;
};

export type PageAddRevisionInput = {
content: Scalars['String']['input'];
pageId: Scalars['Int']['input'];
title: Scalars['String']['input'];
};

export type PageInfo = {
__typename?: 'PageInfo';
endCursor?: Maybe<Scalars['String']['output']>;
hasNextPage: Scalars['Boolean']['output'];
};

export type PageMutation = {
__typename?: 'PageMutation';
addRevision: DefaultResponse;
checkoutRevision: DefaultResponse;
create: DefaultResponse;
};


export type PageMutationAddRevisionArgs = {
input: PageAddRevisionInput;
};


export type PageMutationCheckoutRevisionArgs = {
input: CheckoutRevisionInput;
};


export type PageMutationCreateArgs = {
input: CreatePageInput;
};

export type PageQuery = {
__typename?: 'PageQuery';
pages: Array<Page>;
Expand Down Expand Up @@ -1991,7 +1953,6 @@ export type ResolversTypes = {
CreateEntityLinkNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateEntityLinkNotificationEvent, 'actor' | 'child' | 'parent'> & { actor: ResolversTypes['User'], child: ResolversTypes['AbstractEntity'], parent: ResolversTypes['AbstractEntity'] }>>;
CreateEntityNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateEntityNotificationEvent, 'actor' | 'entity'> & { actor: ResolversTypes['User'], entity: ResolversTypes['AbstractEntity'] }>>;
CreateEntityRevisionNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateEntityRevisionNotificationEvent, 'actor' | 'entity' | 'entityRevision'> & { actor: ResolversTypes['User'], entity: ResolversTypes['AbstractRepository'], entityRevision: ResolversTypes['AbstractRevision'] }>>;
CreatePageInput: ResolverTypeWrapper<ModelOf<CreatePageInput>>;
CreateTaxonomyLinkNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateTaxonomyLinkNotificationEvent, 'actor' | 'child' | 'parent'> & { actor: ResolversTypes['User'], child: ResolversTypes['AbstractUuid'], parent: ResolversTypes['TaxonomyTerm'] }>>;
CreateTaxonomyTermNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateTaxonomyTermNotificationEvent, 'actor' | 'taxonomyTerm'> & { actor: ResolversTypes['User'], taxonomyTerm: ResolversTypes['TaxonomyTerm'] }>>;
CreateThreadNotificationEvent: ResolverTypeWrapper<ModelOf<Omit<CreateThreadNotificationEvent, 'actor' | 'object' | 'thread'> & { actor: ResolversTypes['User'], object: ResolversTypes['AbstractUuid'], thread: ResolversTypes['Thread'] }>>;
Expand Down Expand Up @@ -2032,9 +1993,7 @@ export type ResolversTypes = {
OauthAcceptResponse: ResolverTypeWrapper<ModelOf<OauthAcceptResponse>>;
OauthMutation: ResolverTypeWrapper<ModelOf<OauthMutation>>;
Page: ResolverTypeWrapper<ModelOf<Omit<Page, 'currentRevision' | 'revisions' | 'taxonomyTerms' | 'threads'> & { currentRevision?: Maybe<ResolversTypes['PageRevision']>, revisions: ResolversTypes['PageRevisionConnection'], taxonomyTerms: ResolversTypes['TaxonomyTermConnection'], threads: ResolversTypes['ThreadConnection'] }>>;
PageAddRevisionInput: ResolverTypeWrapper<ModelOf<PageAddRevisionInput>>;
PageInfo: ResolverTypeWrapper<ModelOf<PageInfo>>;
PageMutation: ResolverTypeWrapper<ModelOf<Omit<PageMutation, 'addRevision' | 'checkoutRevision' | 'create'> & { addRevision: ResolversTypes['DefaultResponse'], checkoutRevision: ResolversTypes['DefaultResponse'], create: ResolversTypes['DefaultResponse'] }>>;
PageQuery: ResolverTypeWrapper<ModelOf<Omit<PageQuery, 'pages'> & { pages: Array<ResolversTypes['Page']> }>>;
PageRevision: ResolverTypeWrapper<ModelOf<Omit<PageRevision, 'author' | 'repository' | 'threads'> & { author: ResolversTypes['User'], repository: ResolversTypes['Page'], threads: ResolversTypes['ThreadConnection'] }>>;
PageRevisionConnection: ResolverTypeWrapper<ModelOf<Omit<PageRevisionConnection, 'nodes'> & { nodes: Array<ResolversTypes['PageRevision']> }>>;
Expand Down Expand Up @@ -2140,7 +2099,6 @@ export type ResolversParentTypes = {
CreateEntityLinkNotificationEvent: ModelOf<Omit<CreateEntityLinkNotificationEvent, 'actor' | 'child' | 'parent'> & { actor: ResolversParentTypes['User'], child: ResolversParentTypes['AbstractEntity'], parent: ResolversParentTypes['AbstractEntity'] }>;
CreateEntityNotificationEvent: ModelOf<Omit<CreateEntityNotificationEvent, 'actor' | 'entity'> & { actor: ResolversParentTypes['User'], entity: ResolversParentTypes['AbstractEntity'] }>;
CreateEntityRevisionNotificationEvent: ModelOf<Omit<CreateEntityRevisionNotificationEvent, 'actor' | 'entity' | 'entityRevision'> & { actor: ResolversParentTypes['User'], entity: ResolversParentTypes['AbstractRepository'], entityRevision: ResolversParentTypes['AbstractRevision'] }>;
CreatePageInput: ModelOf<CreatePageInput>;
CreateTaxonomyLinkNotificationEvent: ModelOf<Omit<CreateTaxonomyLinkNotificationEvent, 'actor' | 'child' | 'parent'> & { actor: ResolversParentTypes['User'], child: ResolversParentTypes['AbstractUuid'], parent: ResolversParentTypes['TaxonomyTerm'] }>;
CreateTaxonomyTermNotificationEvent: ModelOf<Omit<CreateTaxonomyTermNotificationEvent, 'actor' | 'taxonomyTerm'> & { actor: ResolversParentTypes['User'], taxonomyTerm: ResolversParentTypes['TaxonomyTerm'] }>;
CreateThreadNotificationEvent: ModelOf<Omit<CreateThreadNotificationEvent, 'actor' | 'object' | 'thread'> & { actor: ResolversParentTypes['User'], object: ResolversParentTypes['AbstractUuid'], thread: ResolversParentTypes['Thread'] }>;
Expand Down Expand Up @@ -2179,9 +2137,7 @@ export type ResolversParentTypes = {
OauthAcceptResponse: ModelOf<OauthAcceptResponse>;
OauthMutation: ModelOf<OauthMutation>;
Page: ModelOf<Omit<Page, 'currentRevision' | 'revisions' | 'taxonomyTerms' | 'threads'> & { currentRevision?: Maybe<ResolversParentTypes['PageRevision']>, revisions: ResolversParentTypes['PageRevisionConnection'], taxonomyTerms: ResolversParentTypes['TaxonomyTermConnection'], threads: ResolversParentTypes['ThreadConnection'] }>;
PageAddRevisionInput: ModelOf<PageAddRevisionInput>;
PageInfo: ModelOf<PageInfo>;
PageMutation: ModelOf<Omit<PageMutation, 'addRevision' | 'checkoutRevision' | 'create'> & { addRevision: ResolversParentTypes['DefaultResponse'], checkoutRevision: ResolversParentTypes['DefaultResponse'], create: ResolversParentTypes['DefaultResponse'] }>;
PageQuery: ModelOf<Omit<PageQuery, 'pages'> & { pages: Array<ResolversParentTypes['Page']> }>;
PageRevision: ModelOf<Omit<PageRevision, 'author' | 'repository' | 'threads'> & { author: ResolversParentTypes['User'], repository: ResolversParentTypes['Page'], threads: ResolversParentTypes['ThreadConnection'] }>;
PageRevisionConnection: ModelOf<Omit<PageRevisionConnection, 'nodes'> & { nodes: Array<ResolversParentTypes['PageRevision']> }>;
Expand Down Expand Up @@ -2824,7 +2780,6 @@ export type MutationResolvers<ContextType = Context, ParentType extends Resolver
experiment?: Resolver<ResolversTypes['ExperimentMutation'], ParentType, ContextType>;
notification?: Resolver<ResolversTypes['NotificationMutation'], ParentType, ContextType>;
oauth?: Resolver<ResolversTypes['OauthMutation'], ParentType, ContextType>;
page?: Resolver<ResolversTypes['PageMutation'], ParentType, ContextType>;
subscription?: Resolver<ResolversTypes['SubscriptionMutation'], ParentType, ContextType>;
taxonomyTerm?: Resolver<ResolversTypes['TaxonomyTermMutation'], ParentType, ContextType>;
thread?: Resolver<ResolversTypes['ThreadMutation'], ParentType, ContextType>;
Expand Down Expand Up @@ -2887,13 +2842,6 @@ export type PageInfoResolvers<ContextType = Context, ParentType extends Resolver
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type PageMutationResolvers<ContextType = Context, ParentType extends ResolversParentTypes['PageMutation'] = ResolversParentTypes['PageMutation']> = {
addRevision?: Resolver<ResolversTypes['DefaultResponse'], ParentType, ContextType, RequireFields<PageMutationAddRevisionArgs, 'input'>>;
checkoutRevision?: Resolver<ResolversTypes['DefaultResponse'], ParentType, ContextType, RequireFields<PageMutationCheckoutRevisionArgs, 'input'>>;
create?: Resolver<ResolversTypes['DefaultResponse'], ParentType, ContextType, RequireFields<PageMutationCreateArgs, 'input'>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type PageQueryResolvers<ContextType = Context, ParentType extends ResolversParentTypes['PageQuery'] = ResolversParentTypes['PageQuery']> = {
pages?: Resolver<Array<ResolversTypes['Page']>, ParentType, ContextType, Partial<PageQueryPagesArgs>>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
Expand Down Expand Up @@ -3338,7 +3286,6 @@ export type Resolvers<ContextType = Context> = {
OauthMutation?: OauthMutationResolvers<ContextType>;
Page?: PageResolvers<ContextType>;
PageInfo?: PageInfoResolvers<ContextType>;
PageMutation?: PageMutationResolvers<ContextType>;
PageQuery?: PageQueryResolvers<ContextType>;
PageRevision?: PageRevisionResolvers<ContextType>;
PageRevisionConnection?: PageRevisionConnectionResolvers<ContextType>;
Expand Down

0 comments on commit bb04d26

Please sign in to comment.