Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/models/page.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export type PageContextT = (
displayField: string;
};

/** Interface for the page geographic context */
export type PageGeographicContextT = {
enabled: boolean;
region?: string;
country?: string;
};

/** Page documents interface declaration */
export interface Page extends Document {
kind: 'Page';
Expand All @@ -45,6 +52,7 @@ export interface Page extends Document {
) & {
content: mongoose.Types.ObjectId | Form | Workflow | Dashboard;
})[];
geographicContext: PageGeographicContextT;
permissions?: {
canSee?: (mongoose.Types.ObjectId | Role)[];
canUpdate?: (mongoose.Types.ObjectId | Role)[];
Expand Down Expand Up @@ -90,6 +98,14 @@ const pageSchema = new Schema<Page>(
_id: false,
},
],
geographicContext: {
enabled: {
type: Boolean,
default: false,
},
region: String,
country: String,
},
permissions: {
canSee: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/schema/inputs/pageContext.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'graphql';
import { Types } from 'mongoose';

/** Aggregation type for queries/mutations argument */
/** Page context type for queries/mutations argument */
export type PageContextArgs = {
refData?: string | Types.ObjectId;
resource: Types.ObjectId;
Expand Down
18 changes: 18 additions & 0 deletions src/schema/inputs/pageGeographicContext.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GraphQLBoolean, GraphQLInputObjectType, GraphQLString } from 'graphql';

/** Page geographic context type for queries/mutations argument */
export type PageGeographicContextArgs = {
enabled?: boolean;
region?: string;
country?: string;
};

/** GraphQL Input Type for the page geographic context */
export const PageGeographicContextInputType = new GraphQLInputObjectType({
name: 'PageGeographicContextInputType',
fields: () => ({
enabled: { type: GraphQLBoolean },
region: { type: GraphQLString },
country: { type: GraphQLString },
}),
});
17 changes: 17 additions & 0 deletions src/schema/mutation/editPage.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { logger } from '@services/logger.service';
import { graphQLAuthCheck } from '@schema/shared';
import { Types } from 'mongoose';
import { Context } from '@server/apollo/context';
import {
PageGeographicContextArgs,
PageGeographicContextInputType,
} from '@schema/inputs/pageGeographicContext.input';

/** Simple form permission change type */
type SimplePermissionChange =
Expand All @@ -38,6 +42,7 @@ type EditPageArgs = {
permissions?: any;
icon?: string;
visible?: boolean;
geographicContext?: PageGeographicContextArgs;
};

/**
Expand All @@ -53,6 +58,7 @@ export default {
icon: { type: GraphQLString },
permissions: { type: GraphQLJSON },
visible: { type: GraphQLBoolean },
geographicContext: { type: PageGeographicContextInputType },
},
async resolve(parent, args: EditPageArgs, context: Context) {
graphQLAuthCheck(context);
Expand Down Expand Up @@ -125,6 +131,17 @@ export default {
// Update visibility
Object.assign(update, !isNil(args.visible) && { visible: args.visible });

// Update geographic context
if (!isNil(args.geographicContext)) {
const geographicContext = page.geographicContext;
Object.assign(update, {
geographicContext: {
...geographicContext,
...args.geographicContext,
},
});
}

// apply the update
page = await Page.findByIdAndUpdate(
page._id,
Expand Down
8 changes: 8 additions & 0 deletions src/schema/types/page.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export const PageType = new GraphQLObjectType({
return null;
},
},
geographicContext: {
type: GraphQLJSON,
async resolve(parent, args, context) {
const ability = await extendAbilityForPage(context.user, parent);
if (ability.can('read', parent)) return parent.geographicContext;
return null;
},
},
permissions: {
type: AccessType,
async resolve(parent, args, context) {
Expand Down