mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Update CopilotActionAPI to include permission checks for create, read, delete, and update actions
This commit is contained in:
parent
10eb7239dc
commit
e11ab9ee5c
@ -25,15 +25,30 @@ import ColumnLength from "../../Types/Database/ColumnLength";
|
||||
@EnableDocumentation()
|
||||
@TenantColumn("projectId")
|
||||
@TableAccessControl({
|
||||
create: [],
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CreateCopilotAction,
|
||||
],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.ReadCopilotAction,
|
||||
],
|
||||
delete: [],
|
||||
update: [],
|
||||
delete: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.DeleteCopilotAction,
|
||||
],
|
||||
update: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.EditCopilotAction,
|
||||
],
|
||||
})
|
||||
@EnableWorkflow({
|
||||
create: true,
|
||||
|
@ -237,9 +237,7 @@ export default class CopilotActionAPI extends BaseAPI<
|
||||
?.toString()}/update-copilot-action/:secretkey`,
|
||||
CodeRepositoryAuthorization.isAuthorizedRepository,
|
||||
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
|
||||
|
||||
try {
|
||||
|
||||
const secretkey: string = req.params["secretkey"]!;
|
||||
|
||||
if (!secretkey) {
|
||||
@ -274,7 +272,7 @@ export default class CopilotActionAPI extends BaseAPI<
|
||||
commitHash,
|
||||
statusMessage,
|
||||
logs,
|
||||
actionId
|
||||
actionId,
|
||||
}: {
|
||||
actionStatus: CopilotActionStatus;
|
||||
pullRequestId?: ObjectID | undefined;
|
||||
@ -284,18 +282,19 @@ export default class CopilotActionAPI extends BaseAPI<
|
||||
actionId: ObjectID;
|
||||
} = req.body;
|
||||
|
||||
const exisingAction = await CopilotActionService.findOneBy({
|
||||
query: {
|
||||
_id: actionId,
|
||||
codeRepositoryId: codeRepository.id!,
|
||||
},
|
||||
select: {
|
||||
_id: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
const exisingAction: CopilotAction | null =
|
||||
await CopilotActionService.findOneBy({
|
||||
query: {
|
||||
_id: actionId,
|
||||
codeRepositoryId: codeRepository.id!,
|
||||
},
|
||||
select: {
|
||||
_id: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!exisingAction) {
|
||||
throw new BadDataException("Action not found");
|
||||
|
@ -3,6 +3,12 @@ import { OnCreate } from "../Types/Database/Hooks";
|
||||
import DatabaseService from "./DatabaseService";
|
||||
import ObjectID from "../../Types/ObjectID";
|
||||
import Model from "Common/Models/DatabaseModels/CopilotCodeRepository";
|
||||
import {
|
||||
CopilotActionTypeData,
|
||||
CopilotActionTypeUtil,
|
||||
} from "../../Types/Copilot/CopilotActionType";
|
||||
import CopilotActionTypePriority from "../../Models/DatabaseModels/CopilotActionTypePriority";
|
||||
import CopilotActionTypePriorityService from "./CopilotActionTypePriorityService";
|
||||
|
||||
export class Service extends DatabaseService<Model> {
|
||||
public constructor() {
|
||||
@ -19,6 +25,36 @@ export class Service extends DatabaseService<Model> {
|
||||
createBy: createBy,
|
||||
};
|
||||
}
|
||||
|
||||
protected override async onCreateSuccess(
|
||||
_onCreate: OnCreate<Model>,
|
||||
createdItem: Model,
|
||||
): Promise<Model> {
|
||||
// add all the actions.
|
||||
|
||||
const repo: Model = createdItem;
|
||||
|
||||
const defaultCopilotActionTypes: Array<CopilotActionTypeData> =
|
||||
CopilotActionTypeUtil.getAllCopilotActionTypes();
|
||||
|
||||
for (const defaultAction of defaultCopilotActionTypes) {
|
||||
const copilotActionTypePriority: CopilotActionTypePriority =
|
||||
new CopilotActionTypePriority();
|
||||
copilotActionTypePriority.projectId = repo.projectId!;
|
||||
copilotActionTypePriority.actionType = defaultAction.type;
|
||||
copilotActionTypePriority.priority = defaultAction.defaultPriority;
|
||||
copilotActionTypePriority.codeRepositoryId = repo.id!;
|
||||
|
||||
await CopilotActionTypePriorityService.create({
|
||||
data: copilotActionTypePriority,
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return createdItem;
|
||||
}
|
||||
}
|
||||
|
||||
export default new Service();
|
||||
|
@ -19,13 +19,12 @@ export default class ImproveComments extends CopilotActionBase {
|
||||
this.acceptFileExtentions = CodeRepositoryUtil.getCodeFileExtentions();
|
||||
}
|
||||
|
||||
protected override async isActionRequired(data: {
|
||||
protected override async isActionRequired(_data: {
|
||||
copilotActionProp: FileActionProp;
|
||||
}): Promise<boolean> {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override isActionComplete(_data: CopilotProcess): Promise<boolean> {
|
||||
return Promise.resolve(this.isRequirementsMet);
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ export default class CopilotActionService {
|
||||
commitHash: data.commitHash,
|
||||
statusMessage: data.statusMessage,
|
||||
logs: data.logs,
|
||||
actionId: data.copilotActonId
|
||||
actionId: data.copilotActonId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user