From cd3c4b2082134316bf1574f80e0c67b18cb7ca19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Tue, 26 Sep 2023 04:21:36 +0900 Subject: [PATCH] refactor: `enableAccessControl` to `publicAccessControl` ref: https://github.com/ubiquity/ubiquibot/pull/697#discussion_r1320831528 --- src/bindings/config.ts | 4 ++-- src/configs/ubiquibot-config-default.ts | 10 +++++++--- src/handlers/access/labels-access.ts | 4 ++-- src/handlers/payout/action.ts | 4 ++-- src/handlers/pricing/action.ts | 2 +- src/types/config.ts | 14 +++++++------- src/utils/private.ts | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/bindings/config.ts b/src/bindings/config.ts index 8022b814b..696827f82 100644 --- a/src/bindings/config.ts +++ b/src/bindings/config.ts @@ -33,7 +33,7 @@ export const loadConfig = async (context: Context): Promise => { assistivePricing, registerWalletWithVerification, staleBountyTime, - enableAccessControl, + publicAccessControl, openAIKey, openAITokenLimit, newContributorGreeting, @@ -106,7 +106,7 @@ export const loadConfig = async (context: Context): Promise => { apiKey: openAIKey, tokenLimit: openAITokenLimit || 0, }, - accessControl: enableAccessControl, + publicAccessControl: publicAccessControl, newContributorGreeting: newContributorGreeting, }; diff --git a/src/configs/ubiquibot-config-default.ts b/src/configs/ubiquibot-config-default.ts index 54beb36a8..eba5d43ac 100644 --- a/src/configs/ubiquibot-config-default.ts +++ b/src/configs/ubiquibot-config-default.ts @@ -93,10 +93,14 @@ export const DefaultConfig: MergedConfig = { }, }, }, - enableAccessControl: { - label: true, - organization: true, + publicAccessControl: { + setLabel: true, + fundExternalClosedIssue: true, }, + + // "public-access-control": { + // "set-label": false, + // "fund-external-closed-issue": false staleBountyTime: "0d", newContributorGreeting: { enabled: false, diff --git a/src/handlers/access/labels-access.ts b/src/handlers/access/labels-access.ts index 228aa5a38..2354b0742 100644 --- a/src/handlers/access/labels-access.ts +++ b/src/handlers/access/labels-access.ts @@ -4,8 +4,8 @@ import { addCommentToIssue, getUserPermission, removeLabel, addLabelToIssue } fr import { Payload } from "../../types"; export const handleLabelsAccess = async () => { - const { accessControl } = getBotConfig(); - if (!accessControl.label) return true; + const { publicAccessControl: accessControl } = getBotConfig(); + if (!accessControl.setLabel) return true; const context = getBotContext(); const logger = getLogger(); diff --git a/src/handlers/payout/action.ts b/src/handlers/payout/action.ts index 855b6242f..bba9036d9 100644 --- a/src/handlers/payout/action.ts +++ b/src/handlers/payout/action.ts @@ -67,7 +67,7 @@ export const incentivesCalculation = async (): Promise => { } const valid = await handleLabelsAccess(); - if (!valid && config.accessControl.label) { + if (!valid && config.publicAccessControl.setLabel) { return; } diff --git a/src/types/config.ts b/src/types/config.ts index 9ac5105f8..bbb560e77 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -125,12 +125,12 @@ export const WalletSchema = Type.Object({ registerWalletWithVerification: Type.Boolean(), }); -export const AccessControlSchema = Type.Object({ - label: Type.Boolean(), - organization: Type.Boolean(), +export const PublicAccessControlSchema = Type.Object({ + setLabel: Type.Boolean(), + fundExternalClosedIssue: Type.Boolean(), }); -export type AccessControl = Static; +export type AccessControl = Static; export const BotConfigSchema = Type.Object({ log: LogConfigSchema, @@ -146,7 +146,7 @@ export const BotConfigSchema = Type.Object({ command: CommandConfigSchema, wallet: WalletSchema, ask: AskSchema, - accessControl: AccessControlSchema, + publicAccessControl: PublicAccessControlSchema, newContributorGreeting: NewContributorGreetingSchema, }); @@ -187,7 +187,7 @@ export const WideConfigSchema = Type.Object( incentives: Type.Optional(IncentivesSchema), defaultLabels: Type.Optional(Type.Array(Type.String())), registerWalletWithVerification: Type.Optional(Type.Boolean()), - enableAccessControl: Type.Optional(AccessControlSchema), + enableAccessControl: Type.Optional(PublicAccessControlSchema), openAIKey: Type.Optional(Type.String()), openAITokenLimit: Type.Optional(Type.Number()), staleBountyTime: Type.Optional(Type.String()), @@ -220,7 +220,7 @@ export const MergedConfigSchema = Type.Object({ incentives: IncentivesSchema, defaultLabels: Type.Array(Type.String()), registerWalletWithVerification: Type.Boolean(), - enableAccessControl: AccessControlSchema, + publicAccessControl: PublicAccessControlSchema, openAIKey: Type.Optional(Type.String()), openAITokenLimit: Type.Optional(Type.Number()), staleBountyTime: Type.String(), diff --git a/src/utils/private.ts b/src/utils/private.ts index 776acbaa6..28ceff031 100644 --- a/src/utils/private.ts +++ b/src/utils/private.ts @@ -157,7 +157,7 @@ export const getWideConfig = async (context: Context) => { defaultLabels: mergedConfigData.defaultLabels, promotionComment: mergedConfigData.promotionComment, registerWalletWithVerification: mergedConfigData.registerWalletWithVerification, - enableAccessControl: mergedConfigData.enableAccessControl, + publicAccessControl: mergedConfigData.publicAccessControl, openAIKey: mergedConfigData.openAIKey, openAITokenLimit: mergedConfigData.openAITokenLimit, staleBountyTime: mergedConfigData.staleBountyTime,