Skip to content

Commit

Permalink
refactor: enableAccessControl to publicAccessControl
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Sep 25, 2023
1 parent db3685b commit cd3c4b2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
assistivePricing,
registerWalletWithVerification,
staleBountyTime,
enableAccessControl,
publicAccessControl,
openAIKey,
openAITokenLimit,
newContributorGreeting,
Expand Down Expand Up @@ -106,7 +106,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
apiKey: openAIKey,
tokenLimit: openAITokenLimit || 0,
},
accessControl: enableAccessControl,
publicAccessControl: publicAccessControl,
newContributorGreeting: newContributorGreeting,
};

Expand Down
10 changes: 7 additions & 3 deletions src/configs/ubiquibot-config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/access/labels-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/payout/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const incentivesCalculation = async (): Promise<IncentivesCalculationResu
payout: { paymentToken, rpc, permitBaseUrl, evmNetworkId, privateKey },
mode: { incentiveMode, permitMaxPrice },
price: { incentives, issueCreatorMultiplier, baseMultiplier },
accessControl,
publicAccessControl: accessControl,
} = getBotConfig();
const logger = getLogger();
const payload = context.payload as Payload;
Expand All @@ -80,7 +80,7 @@ export const incentivesCalculation = async (): Promise<IncentivesCalculationResu
throw new Error("Permit generation skipped because issue is undefined");
}

if (accessControl.organization) {
if (accessControl.fundExternalClosedIssue) {
const userHasPermission = await checkUserPermissionForRepoAndOrg(payload.sender.login, context);

if (!userHasPermission) {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/pricing/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const pricingLabelLogic = async (): Promise<void> => {
}
const valid = await handleLabelsAccess();

if (!valid && config.accessControl.label) {
if (!valid && config.publicAccessControl.setLabel) {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof AccessControlSchema>;
export type AccessControl = Static<typeof PublicAccessControlSchema>;

export const BotConfigSchema = Type.Object({
log: LogConfigSchema,
Expand All @@ -146,7 +146,7 @@ export const BotConfigSchema = Type.Object({
command: CommandConfigSchema,
wallet: WalletSchema,
ask: AskSchema,
accessControl: AccessControlSchema,
publicAccessControl: PublicAccessControlSchema,
newContributorGreeting: NewContributorGreetingSchema,
});

Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cd3c4b2

Please sign in to comment.