Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

feat: access control config #696

Merged
Merged
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
2 changes: 2 additions & 0 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
commandSettings,
assistivePricing,
registerWalletWithVerification,
enableAccessControl,
} = await getWideConfig(context);

const publicKey = await getScalarKey(process.env.X25519_PRIVATE_KEY);
Expand Down Expand Up @@ -97,6 +98,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
wallet: {
registerWalletWithVerification: registerWalletWithVerification,
},
accessControl: enableAccessControl,
};

if (botConfig.payout.privateKey == "") {
Expand Down
5 changes: 4 additions & 1 deletion src/handlers/access/labels-access.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { getAccessLevel } from "../../adapters/supabase";
import { getBotContext, getLogger } from "../../bindings";
import { getBotConfig, getBotContext, getLogger } from "../../bindings";
import { addCommentToIssue, getUserPermission, removeLabel, addLabelToIssue } from "../../helpers";
import { Payload } from "../../types";

export const handleLabelsAccess = async () => {
const { accessControl } = getBotConfig();
if (!accessControl.label) return;

const context = getBotContext();
const logger = getLogger();
const payload = context.payload as Payload;
Expand Down
7 changes: 7 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export const WalletSchema = Type.Object({
registerWalletWithVerification: Type.Boolean(),
});

export const AccessControlSchema = Type.Object({
label: Type.Boolean(),
});

export type AccessControl = Static<typeof AccessControlSchema>;

export const BotConfigSchema = Type.Object({
log: LogConfigSchema,
price: PriceConfigSchema,
Expand All @@ -106,6 +112,7 @@ export const BotConfigSchema = Type.Object({
comments: CommentsSchema,
command: CommandConfigSchema,
wallet: WalletSchema,
accessControl: AccessControlSchema,
});

export type BotConfig = Static<typeof BotConfigSchema>;
11 changes: 11 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Incentives } from "./private";
import { Level } from "../adapters/supabase";
import { CommandObj, WideLabel, WideOrgConfig, WideRepoConfig } from "./private";
import { AccessControl } from "../types";

interface Configs {
parsedRepo?: WideRepoConfig;
Expand Down Expand Up @@ -183,3 +184,13 @@ export const getRegisterWalletWithVerification = ({ parsedRepo, parsedOrg, parse
return Boolean(parsedDefault["register-wallet-with-verification"]);
}
};

export const getEnableAccessControl = ({ parsedRepo, parsedOrg, parsedDefault }: Configs): AccessControl => {
if (parsedRepo && parsedRepo["enable-access-control"]) {
return parsedRepo["enable-access-control"];
} else if (parsedOrg && parsedOrg["enable-access-control"]) {
return parsedOrg["enable-access-control"];
} else {
return parsedDefault["enable-access-control"] as AccessControl;
}
};
5 changes: 4 additions & 1 deletion src/utils/private.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _sodium from "libsodium-wrappers";
import YAML from "yaml";
import { Payload } from "../types";
import { AccessControl, Payload } from "../types";
import { Context } from "probot";
import {
getAnalyticsMode,
Expand All @@ -18,6 +18,7 @@ import {
getAssistivePricing,
getCommandSettings,
getRegisterWalletWithVerification,
getEnableAccessControl,
} from "./helpers";

import DEFAULT_CONFIG_JSON from "../../ubiquibot-config-default.json";
Expand Down Expand Up @@ -83,6 +84,7 @@ export interface WideConfig {
incentives?: Incentives;
"default-labels"?: string[];
"register-wallet-with-verification"?: boolean;
"enable-access-control"?: AccessControl;
}

export type WideRepoConfig = WideConfig;
Expand Down Expand Up @@ -182,6 +184,7 @@ export const getWideConfig = async (context: Context) => {
defaultLabels: getDefaultLabels(configs),
promotionComment: getPromotionComment(configs),
registerWalletWithVerification: getRegisterWalletWithVerification(configs),
enableAccessControl: getEnableAccessControl(configs),
};

return configData;
Expand Down
3 changes: 3 additions & 0 deletions ubiquibot-config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@
"word": 0
}
}
},
"enable-access-control": {
"label": false
}
}