Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCC-1523 Add collaborator and visibility management commands. #292

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions packages/cli/src/cli/commands/sites/collaborators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ora from "ora";
import AddOnApiHelper from "../../../lib/addonApiHelper";
import { errorHandler } from "../../exceptions";

type listCollaboratorsSchemaParams = { siteId: string };
export const listCollaborators = errorHandler<listCollaboratorsSchemaParams>(
async ({ siteId }: listCollaboratorsSchemaParams) => {
const spinner = ora("Retrieving Collaborators...").start();
const result = await AddOnApiHelper.listCollaborators(siteId);
spinner.succeed();
console.log(JSON.stringify(result, null, 4));
},
);

type removeCollaboratorschemaParams = { siteId: string; email: string };
export const removeCollaborator = errorHandler<removeCollaboratorschemaParams>(
async ({ siteId, email }: removeCollaboratorschemaParams) => {
const spinner = ora("Removing Collaborator...").start();
await AddOnApiHelper.removeCollaborator(siteId, email);
spinner.succeed();
},
);

type addCollaboratorschemaParams = { siteId: string; email: string };
export const addCollaborator = errorHandler<addCollaboratorschemaParams>(
async ({ siteId, email }: addCollaboratorschemaParams) => {
const spinner = ora("Adding Collaborator...").start();
await AddOnApiHelper.addCollaborator(siteId, email);
spinner.succeed();
},
);
8 changes: 8 additions & 0 deletions packages/cli/src/cli/commands/sites/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
type: "string",
},
},
{
id: "visibility",
command: {
name: "visibility <visibility>",
description: "Set the collection's visibility (either 'private' or 'workspace')",

Check failure on line 140 in packages/cli/src/cli/commands/sites/site.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·······`
type: "string",
},
},
] as const;

export const SITE_EXAMPLES = [
Expand Down
100 changes: 100 additions & 0 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import {
listAdminsSchema,
removeAdminSchema,
} from "./commands/sites/admins";
import {
addCollaborator,
listCollaborators,
removeCollaborator,
} from "./commands/sites/collaborators";
import {
getComponentSchema,
printLiveComponentSchema,
Expand Down Expand Up @@ -599,6 +604,101 @@ yargs(hideBin(process.argv))
);
},
)
.command(
"publishing <cmd> [options]",
"Manage publishing permissions.",
(yargs) => {
yargs
.strictCommands()
.demandCommand()
.command(
"config [options]",
"Update the collection's visibility.",
(yargs) => {
yargs
.strictCommands()
.option("siteId", {
describe: "The id of the collection to modify.",
demandOption: true,
type: "string",
})
.option("mode", {
describe:
"The visibility of this collection (either 'private' or 'workspace').",
demandOption: true,
type: "string",
});
},
async (args) =>
await updateSiteConfig({
id: args.siteId as string,
visibility: args.mode as string,
}),
)
.command(
"list-user [options]",
"Print the users added as collaborators to this collection.",
(yargs) => {
yargs.strictCommands().option("siteId", {
describe: "The id of the collection to modify.",
demandOption: true,
type: "string",
});
},
async (args) =>
await listCollaborators({
siteId: args.siteId as string,
}),
)
.command(
"add-user [options]",
"Update the collection's visibility.",
(yargs) => {
yargs
.strictCommands()
.option("siteId", {
describe: "The id of the collection to modify.",
demandOption: true,
type: "string",
})
.option("user", {
describe: "The email of the user to add.",
demandOption: true,
type: "string",
});
},
async (args) =>
await addCollaborator({
siteId: args.siteId as string,
email: args.user as string,
}),
)
.command(
"remove-user [options]",
"Update the collection's visibility.",
(yargs) => {
yargs
.strictCommands()
.option("siteId", {
describe: "The id of the collection to modify.",
demandOption: true,
type: "string",
})
.option("user", {
describe: "The email of the user to remove.",
demandOption: true,
type: "string",
});
},
async (args) =>
await removeCollaborator({
siteId: args.siteId as string,
email: args.user as string,
}),
);
},
async (args) => await createSite(args.url as string),
)
.example(formatExamples(SITE_EXAMPLES));
},
async () => {
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/lib/addonApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,53 @@
});
}

static async listCollaborators(id: string): Promise<void> {
const idToken = await this.getIdToken();

return (
await axios.get(
`${(await getApiConfig()).SITE_ENDPOINT}/${id}/collaborators`,
{
headers: {
Authorization: `Bearer ${idToken}`,
},
Dismissed Show dismissed Hide dismissed
},
)
).data;
}

static async addCollaborator(id: string, email: string): Promise<void> {
const idToken = await this.getIdToken();

await axios.patch(
`${(await getApiConfig()).SITE_ENDPOINT}/${id}/collaborators`,
{
email,
},
{
headers: {
Authorization: `Bearer ${idToken}`,
},
Dismissed Show dismissed Hide dismissed
},
);
}

static async removeCollaborator(id: string, email: string): Promise<void> {
const idToken = await this.getIdToken();

await axios.delete(
`${(await getApiConfig()).SITE_ENDPOINT}/${id}/collaborators`,
{
headers: {
Authorization: `Bearer ${idToken}`,
},
Dismissed Show dismissed Hide dismissed
data: {
email,
},
},
);
}

static async updateSiteConfig(
id: string,
{
Expand Down
Loading