From da86cdad42eecfe988aa7a60c8e764c75ad1688f Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 6 Mar 2021 19:18:22 +0530 Subject: [PATCH] feat(Events): add support for online events --- server/graphql/schemaV1.graphql | 45 ++++++++++++++++++++++ server/graphql/v1/CollectiveInterface.js | 16 ++++++++ server/graphql/v1/inputTypes.js | 1 + server/graphql/v1/mutations/collectives.js | 15 +++++++- server/lib/notifications.js | 2 +- templates/emails/ticket.confirmed.hbs | 15 +++++++- 6 files changed, 91 insertions(+), 3 deletions(-) diff --git a/server/graphql/schemaV1.graphql b/server/graphql/schemaV1.graphql index 9a86843f0e65..648a6aa7c8b8 100644 --- a/server/graphql/schemaV1.graphql +++ b/server/graphql/schemaV1.graphql @@ -114,6 +114,11 @@ type Collective implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -406,6 +411,11 @@ input CollectiveInputType { tiers: [TierInputType] settings: JSON data: JSON + + """ + Private instructions related to an event + """ + privateInstructions: String members: [MemberInputType] notifications: [NotificationInputType] HostCollectiveId: Int @@ -462,6 +472,11 @@ interface CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -1084,6 +1099,11 @@ type Event implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -1451,6 +1471,11 @@ type Fund implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -2478,6 +2503,11 @@ type Organization implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -2857,6 +2887,11 @@ type Project implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -3706,6 +3741,11 @@ type User implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String @@ -3989,6 +4029,11 @@ type Vendor implements CollectiveInterface { """ isPledged: Boolean data: JSON @deprecated(reason: "2020-10-08: This field is not provided anymore and will return an empty object") + + """ + Private instructions related to an event + """ + privateInstructions: String githubContributors: JSON! slug: String path: String diff --git a/server/graphql/v1/CollectiveInterface.js b/server/graphql/v1/CollectiveInterface.js index f992a2f4dac7..cc8defdd484b 100644 --- a/server/graphql/v1/CollectiveInterface.js +++ b/server/graphql/v1/CollectiveInterface.js @@ -652,6 +652,10 @@ export const CollectiveInterfaceType = new GraphQLInterfaceType({ type: GraphQLJSON, deprecationReason: '2020-10-08: This field is not provided anymore and will return an empty object', }, + privateInstructions: { + type: GraphQLString, + description: 'Private instructions related to an event', + }, githubContributors: { type: new GraphQLNonNull(GraphQLJSON) }, slug: { type: GraphQLString }, path: { type: GraphQLString }, @@ -1107,6 +1111,18 @@ const CollectiveFields = () => { return {}; }, }, + privateInstructions: { + type: GraphQLString, + description: 'Private instructions related to an event', + resolve(collective, _, req) { + if ( + collective.type === types.EVENT && + (req.remoteUser?.isAdminOfCollective(collective) || req.remoteUser?.hasRole(roles.PARTICIPANT, collective)) + ) { + return collective.data?.privateInstructions; + } + }, + }, githubContributors: { type: new GraphQLNonNull(GraphQLJSON), resolve(collective) { diff --git a/server/graphql/v1/inputTypes.js b/server/graphql/v1/inputTypes.js index b046acc2dc51..36fa37a4c259 100644 --- a/server/graphql/v1/inputTypes.js +++ b/server/graphql/v1/inputTypes.js @@ -169,6 +169,7 @@ export const CollectiveInputType = new GraphQLInputObjectType({ tiers: { type: new GraphQLList(TierInputType) }, settings: { type: GraphQLJSON }, data: { type: GraphQLJSON, deprecationReason: '2020-10-08: data cannot be edited. This field will be ignored.' }, + privateInstructions: { type: GraphQLString, description: 'Private instructions related to an event' }, members: { type: new GraphQLList(MemberInputType) }, notifications: { type: new GraphQLList(NotificationInputType) }, HostCollectiveId: { type: GraphQLInt }, diff --git a/server/graphql/v1/mutations/collectives.js b/server/graphql/v1/mutations/collectives.js index 41969fe15180..36a2f3ab86f9 100644 --- a/server/graphql/v1/mutations/collectives.js +++ b/server/graphql/v1/mutations/collectives.js @@ -56,6 +56,12 @@ export async function createCollective(_, args, req) { }; } } + // Set private instructions + if (args.collective.privateInstructions) { + collectiveData.data = { + privateInstructions: args.collective.privateInstructions, + }; + } collectiveData.isActive = false; if (args.collective.ParentCollectiveId) { @@ -291,7 +297,7 @@ export function editCollective(_, args, req) { } const newCollectiveData = { - ...omit(args.collective, ['location', 'type', 'ParentCollectiveId', 'data']), + ...omit(args.collective, ['location', 'type', 'ParentCollectiveId', 'data', 'privateInstructions']), LastEditedByUserId: req.remoteUser.id, }; @@ -313,6 +319,13 @@ export function editCollective(_, args, req) { newCollectiveData.countryISO = location.country; } + // Set private instructions value + if (args.collective.privateInstructions) { + newCollectiveData.data = { + privateInstructions: args.collective.privateInstructions, + }; + } + let collective, parentCollective; return req.loaders.Collective.byId diff --git a/server/lib/notifications.js b/server/lib/notifications.js index e1a55b5deb00..68883ec052c8 100644 --- a/server/lib/notifications.js +++ b/server/lib/notifications.js @@ -152,8 +152,8 @@ async function notifyUserId(UserId, activity, options = {}) { } } } - activity.data.event = event.info; + activity.data.isOffline = activity.data.event.locationName !== 'Online'; activity.data.collective = parentCollective.info; options.from = `${parentCollective.name} `; } diff --git a/templates/emails/ticket.confirmed.hbs b/templates/emails/ticket.confirmed.hbs index 8b05693bc8c4..2ed1cb52cc21 100644 --- a/templates/emails/ticket.confirmed.hbs +++ b/templates/emails/ticket.confirmed.hbs @@ -13,7 +13,20 @@ Subject: {{ order.quantity }} {{pluralize "ticket" n=order.quantity}} confirmed

This confirms your {{ order.quantity }} {{pluralize "ticket" n=order.quantity}}{{#if order.totalAmount}} for a total of {{currency order.totalAmount currency=order.currency}}{{/if}}.

-

We are excited that you'll be joining us at {{ event.name }} on {{ moment event.startsAt timezone=event.timezone format="MMMM Do YYYY" }} at {{ moment event.startsAt timezone=event.timezone format="h:mma" }} at {{ event.locationName }} ({{event.address}}).

+

We are excited that you'll be joining us at {{ event.name }} on {{ moment event.startsAt timezone=event.timezone format="MMMM Do YYYY" }} at {{ moment event.startsAt timezone=event.timezone format="h:mma" }} +{{#if isOffline }} + at {{ event.locationName }} ({{event.address}}). +{{else if event.address}} + on {{event.address}}. +{{/if}} +

+ +{{#if event.data.privateInstructions}} +

Private Instructions

+

+ {{event.data.privateInstructions}} +

+{{/if}} {{#if transactionPdf}}

📎 Attachments