Skip to content
Draft
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
33 changes: 33 additions & 0 deletions migrations/20250820000000-add-conversation-visibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

module.exports = {
up: async (queryInterface, DataTypes) => {
await queryInterface.addColumn('Conversations', 'visibility', {
type: DataTypes.ENUM('PUBLIC', 'ADMINS_AND_HOST'),
defaultValue: 'PUBLIC',
allowNull: false,
});

await queryInterface.addColumn('Conversations', 'HostCollectiveId', {
type: DataTypes.INTEGER,
references: { key: 'id', model: 'Collectives' },
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
allowNull: true,
});

await queryInterface.sequelize.query(`
UPDATE "Conversations" SET visibility = 'PUBLIC' WHERE visibility IS NULL
`);

await queryInterface.changeColumn('Conversations', 'visibility', {
type: DataTypes.ENUM('PUBLIC', 'ADMINS_AND_HOST'),
allowNull: false,
});
},

down: async queryInterface => {
await queryInterface.removeColumn('Conversations', 'visibility');
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_Conversations_visibility"');
},
};
33 changes: 27 additions & 6 deletions server/graphql/common/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { pick } from 'lodash';

import FEATURE from '../../constants/feature';
import { hasFeature } from '../../lib/allowed-features';
import models from '../../models';
import Conversation from '../../models/Conversation';
import { FeatureNotSupportedForCollective, NotFound, Unauthorized } from '../errors';
import models, { Collective } from '../../models';
import Conversation, { ConversationVisibility } from '../../models/Conversation';
import { FeatureNotSupportedForCollective, NotFound, Unauthorized, ValidationFailed } from '../errors';

import { checkRemoteUserCanUseConversations } from './scope-check';

Expand All @@ -14,7 +14,9 @@ interface CreateConversationParams {
title: string;
html: string;
CollectiveId: number;
HostCollectiveId?: number;
tags?: string[] | null;
visibility?: ConversationVisibility;
}

/**
Expand All @@ -26,7 +28,7 @@ export const createConversation = async (req: Request, params: CreateConversatio
// For now any authenticated user can create a conversation to any collective
checkRemoteUserCanUseConversations(req);

const { CollectiveId, title, html, tags } = params;
const { CollectiveId, title, html, tags, visibility } = params;

// Collective must exist and be of type `COLLECTIVE`
const collective = await req.loaders.Collective.byId.load(CollectiveId);
Expand All @@ -36,12 +38,31 @@ export const createConversation = async (req: Request, params: CreateConversatio
throw new FeatureNotSupportedForCollective();
}

return Conversation.createWithComment(req.remoteUser, collective, title, html, tags);
// Host collective must exist and be of type `HOST`
let host: Collective | null = null;
if (params.HostCollectiveId) {
host = await req.loaders.Collective.byId.load(params.HostCollectiveId);
if (!host) {
throw new NotFound("This Host doesn't exist or has been deleted");
} else if (!host.isHostAccount) {
throw new ValidationFailed('This Host is not a host');
}

// TODO
// else if (!req.remoteUser.isAdmin(host.id) || !(
// req.remoteUser.isAdmin(collective.id) && collective.HostCollectiveId === host.id
// )) {
// throw new Unauthorized('You are not authorized to create a conversation for this host');
// }
}

return Conversation.createWithComment(req.remoteUser, collective, title, html, tags, visibility, host);
};

interface EditConversationParams {
id: number;
title: string;
visibility?: ConversationVisibility;
}

/**
Expand All @@ -63,5 +84,5 @@ export const editConversation = async (req: Request, params: EditConversationPar
throw new Unauthorized();
}

return conversation.update(pick(params, ['title', 'tags']));
return conversation.update(pick(params, ['title', 'tags', 'visibility']));
};
161 changes: 161 additions & 0 deletions server/graphql/schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 826 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Account.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 831 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Account.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 836 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Account.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 841 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Account.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -3492,6 +3512,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 3519 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Host.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 3524 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Host.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 3529 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Host.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 3534 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Host.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -5413,6 +5453,7 @@
updatedAt: DateTime!
tags: [String]
summary: String!
visibility: ConversationVisibility!

Check notice on line 5456 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Field 'visibility' was added to object type 'Conversation'

Field 'visibility' was added to object type 'Conversation'
account: Account
fromAccount: Account

Expand All @@ -5427,6 +5468,11 @@
comments(limit: Int! = 150, offset: Int! = 0): CommentCollection!
followers(limit: Int! = 10, offset: Int! = 0): AccountCollection!
stats: ConversationStats

"""
The date of the last comment in this conversation
"""
lastCommentDate: DateTime

Check notice on line 5475 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Field 'lastCommentDate' was added to object type 'Conversation'

Field 'lastCommentDate' was added to object type 'Conversation'
}

"""
Expand Down Expand Up @@ -5475,6 +5521,21 @@
PRIVATE_NOTE
}

"""
Conversation visibility levels
"""
enum ConversationVisibility {

Check notice on line 5527 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Type 'ConversationVisibility' was added

Type 'ConversationVisibility' was added
"""
Public conversation visible to everyone
"""
PUBLIC

"""
Private conversation visible only to collective admins and host admins
"""
ADMINS_AND_HOST
}

type HostApplication {
id: String!

Expand Down Expand Up @@ -9412,6 +9473,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 9480 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Bot.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 9485 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Bot.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 9490 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Bot.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 9495 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Bot.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -10365,6 +10446,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 10453 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Collective.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 10458 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Collective.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 10463 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Collective.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 10468 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Collective.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -11876,6 +11977,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 11984 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Event.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 11989 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Event.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 11994 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Event.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 11999 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Event.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -19238,6 +19359,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 19366 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Fund.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 19371 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Fund.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 19376 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Fund.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 19381 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Fund.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down Expand Up @@ -20338,6 +20479,26 @@
Only return conversations matching this tag
"""
tag: String

"""
Only return conversations with this visibility level
"""
visibility: ConversationVisibility

Check warning on line 20486 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'visibility: ConversationVisibility' added to field 'Project.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific account
"""
account: AccountReferenceInput

Check warning on line 20491 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'account: AccountReferenceInput' added to field 'Project.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
Only return conversations for this specific host
"""
host: AccountReferenceInput

Check warning on line 20496 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'host: AccountReferenceInput' added to field 'Project.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.

"""
The order of results
"""
orderBy: ChronologicalOrderInput! = { field: CREATED_AT, direction: DESC }

Check warning on line 20501 in server/graphql/schemaV2.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector - Schema v2

Argument 'orderBy: ChronologicalOrderInput!' (with default value) added to field 'Project.conversations'

Adding a new argument to an existing field may involve a change in resolve function logic that potentially may cause some side effects.
): ConversationCollection!

"""
Expand Down
18 changes: 18 additions & 0 deletions server/graphql/v2/enum/ConversationVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GraphQLEnumType } from 'graphql';

import { ConversationVisibility } from '../../../models/Conversation';

export const GraphQLConversationVisibility = new GraphQLEnumType({
name: 'ConversationVisibility',
description: 'Conversation visibility levels',
values: {
PUBLIC: {
description: 'Public conversation visible to everyone',
value: ConversationVisibility.PUBLIC,
},
ADMINS_AND_HOST: {
description: 'Private conversation visible only to collective admins and host admins',
value: ConversationVisibility.ADMINS_AND_HOST,
},
},
});
Loading
Loading