Skip to content

Commit

Permalink
Executor role implementation. (#4737)
Browse files Browse the repository at this point in the history
* Refactor editor to executer in Authentication service.

Signed-off-by: aryan <[email protected]>

* Refactor editor to executer in GraphQl servers.

Signed-off-by: aryan <[email protected]>

* Changing executor roles.

Signed-off-by: aryan <[email protected]>

* Updation in frontend hooks corresponding to backend refactor.

Signed-off-by: aryan <[email protected]>

* Executer role implementation.

Converted editor roles to executer role in frontend files. And Changed rbacs of the new Executer role.

Signed-off-by: aryan <[email protected]>

* modification of api specs for executor

Signed-off-by: aryan <[email protected]>

* removed executor role from userInfraRegistration and fixed import orders.

Signed-off-by: aryan <[email protected]>

* refactor executer to executor

Signed-off-by: aryan <[email protected]>

* Removing exector permission from launch experiment FE

Signed-off-by: aryan <[email protected]>

* minor fix

Signed-off-by: aryan <[email protected]>

---------

Signed-off-by: aryan <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
  • Loading branch information
aryan-bhokare and namkyu1999 authored Jul 2, 2024
1 parent 9d2c93a commit 9efc00c
Show file tree
Hide file tree
Showing 44 changed files with 119 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func SendInvitation(service services.ApplicationService) gin.HandlerFunc {
}

// Validating member role
if member.Role == nil || (*member.Role != entities.RoleEditor && *member.Role != entities.RoleViewer) {
if member.Role == nil || (*member.Role != entities.RoleExecutor && *member.Role != entities.RoleViewer) {
c.JSON(utils.ErrorStatusCodes[utils.ErrInvalidRole], presenter.CreateErrorResponse(utils.ErrInvalidRole))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestGetProject(t *testing.T) {
Value: primitive.D{
primitive.E{
Key: "$in",
Value: []string{"Owner", "Viewer", "Editor"},
Value: []string{"Owner", "Viewer", "Executor"},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/authentication/pkg/entities/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (member *Member) GetMemberOutput() *Member {
type MemberRole string

const (
RoleOwner MemberRole = "Owner"
RoleEditor MemberRole = "Editor"
RoleViewer MemberRole = "Viewer"
RoleOwner MemberRole = "Owner"
RoleExecutor MemberRole = "Executor"
RoleViewer MemberRole = "Viewer"
)

// Invitation defines the type of the invitation that is sent by the Owner of the project to other users
Expand Down
8 changes: 4 additions & 4 deletions chaoscenter/authentication/pkg/validations/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities"

var MutationRbacRules = map[string][]string{
"sendInvitation": {string(entities.RoleOwner)},
"acceptInvitation": {string(entities.RoleViewer), string(entities.RoleEditor)},
"acceptInvitation": {string(entities.RoleViewer), string(entities.RoleExecutor)},
"declineInvitation": {string(entities.RoleViewer),
string(entities.RoleEditor)},
string(entities.RoleExecutor)},
"removeInvitation": {string(entities.RoleOwner)},
"leaveProject": {string(entities.RoleViewer), string(entities.RoleEditor)},
"leaveProject": {string(entities.RoleViewer), string(entities.RoleExecutor)},
"updateProjectName": {string(entities.RoleOwner)},
"getProject": {string(entities.RoleOwner), string(entities.RoleViewer), string(entities.RoleEditor)},
"getProject": {string(entities.RoleOwner), string(entities.RoleViewer), string(entities.RoleExecutor)},
}
2 changes: 1 addition & 1 deletion chaoscenter/graphql/definitions/shared/project.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ enum Invitation {

enum MemberRole {
Owner
Editor
Executor
Viewer
}
2 changes: 1 addition & 1 deletion chaoscenter/graphql/server/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions chaoscenter/graphql/server/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 37 additions & 37 deletions chaoscenter/graphql/server/pkg/authorization/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,53 +56,53 @@ const (
ListEnvironments RoleQuery = "ListEnvironments"

// Probe
AddProbe RoleQuery = "AddProbe"
DeleteProbe RoleQuery = "DeleteProbe"
UpdateProbe RoleQuery = "UpdateProbe"
GetProbe RoleQuery = "GetProbe"
ListProbes RoleQuery = "ListProbes"
MemberRoleOwnerString = string(model.MemberRoleOwner)
MemberRoleEditorString = string(model.MemberRoleEditor)
MemberRoleViewerString = string(model.MemberRoleViewer)
AddProbe RoleQuery = "AddProbe"
DeleteProbe RoleQuery = "DeleteProbe"
UpdateProbe RoleQuery = "UpdateProbe"
GetProbe RoleQuery = "GetProbe"
ListProbes RoleQuery = "ListProbes"
MemberRoleOwnerString = string(model.MemberRoleOwner)
MemberRoleExecutorString = string(model.MemberRoleExecutor)
MemberRoleViewerString = string(model.MemberRoleViewer)
)

var MutationRbacRules = map[RoleQuery][]string{
UserInfrastructureReg: {MemberRoleOwnerString, MemberRoleEditorString},
CreateChaosExperiment: {MemberRoleOwnerString, MemberRoleEditorString},
ReRunChaosExperiment: {MemberRoleOwnerString, MemberRoleEditorString},
DeleteChaosExperiment: {MemberRoleOwnerString, MemberRoleEditorString},
StopChaosExperiment: {MemberRoleOwnerString, MemberRoleEditorString},
AddChaosHub: {MemberRoleOwnerString, MemberRoleEditorString},
UpdateChaosExperiment: {MemberRoleOwnerString, MemberRoleEditorString},
DeleteInfrastructures: {MemberRoleOwnerString, MemberRoleEditorString},
UpdateChaosHub: {MemberRoleOwnerString, MemberRoleEditorString},
DeleteChaosHub: {MemberRoleOwnerString, MemberRoleEditorString},
UserInfrastructureReg: {MemberRoleOwnerString},
CreateChaosExperiment: {MemberRoleOwnerString},
ReRunChaosExperiment: {MemberRoleOwnerString, MemberRoleExecutorString},
DeleteChaosExperiment: {MemberRoleOwnerString},
StopChaosExperiment: {MemberRoleOwnerString, MemberRoleExecutorString},
AddChaosHub: {MemberRoleOwnerString},
UpdateChaosExperiment: {MemberRoleOwnerString},
DeleteInfrastructures: {MemberRoleOwnerString},
UpdateChaosHub: {MemberRoleOwnerString},
DeleteChaosHub: {MemberRoleOwnerString},
EnableGitOps: {MemberRoleOwnerString},
DisableGitOps: {MemberRoleOwnerString},
UpdateGitOps: {MemberRoleOwnerString},
ListWorkflowRuns: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
GetWorkflowRun: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
ListInfrastructures: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
GetInfrastructure: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
GetManifest: {MemberRoleOwnerString, MemberRoleEditorString},
GetInfraDetails: {MemberRoleOwnerString, MemberRoleEditorString},
ListCharts: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
ListExperiment: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
SaveChaosHub: {MemberRoleOwnerString, MemberRoleEditorString},
ListWorkflowRuns: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
GetWorkflowRun: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
ListInfrastructures: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
GetInfrastructure: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
GetManifest: {MemberRoleOwnerString, MemberRoleExecutorString},
GetInfraDetails: {MemberRoleOwnerString, MemberRoleExecutorString},
ListCharts: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
ListExperiment: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
SaveChaosHub: {MemberRoleOwnerString},
CreateImageRegistry: {MemberRoleOwnerString},
UpdateImageRegistry: {MemberRoleOwnerString},
DeleteImageRegistry: {MemberRoleOwnerString},
GetGitOpsDetails: {MemberRoleOwnerString},
ListImageRegistry: {MemberRoleOwnerString},
GetImageRegistry: {MemberRoleOwnerString},
CreateEnvironment: {MemberRoleOwnerString, MemberRoleEditorString},
UpdateEnvironment: {MemberRoleOwnerString, MemberRoleEditorString},
DeleteEnvironment: {MemberRoleOwnerString, MemberRoleEditorString},
GetEnvironment: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
ListEnvironments: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
AddProbe: {MemberRoleOwnerString, MemberRoleEditorString},
UpdateProbe: {MemberRoleOwnerString, MemberRoleEditorString},
GetProbe: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
ListProbes: {MemberRoleOwnerString, MemberRoleEditorString, MemberRoleViewerString},
DeleteProbe: {MemberRoleOwnerString, MemberRoleEditorString},
CreateEnvironment: {MemberRoleOwnerString},
UpdateEnvironment: {MemberRoleOwnerString},
DeleteEnvironment: {MemberRoleOwnerString},
GetEnvironment: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
ListEnvironments: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
AddProbe: {MemberRoleOwnerString},
UpdateProbe: {MemberRoleOwnerString},
GetProbe: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
ListProbes: {MemberRoleOwnerString, MemberRoleExecutorString, MemberRoleViewerString},
DeleteProbe: {MemberRoleOwnerString},
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type Member struct {
type MemberRole string

const (
RoleOwner MemberRole = "Owner"
RoleEditor MemberRole = "Editor"
RoleViewer MemberRole = "Viewer"
RoleOwner MemberRole = "Owner"
RoleExecutor MemberRole = "Executor"
RoleViewer MemberRole = "Viewer"
)

// Invitation defines the type of the invitation that is sent by the Owner of the project to other users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fetcher, FetcherOptions } from 'services/fetcher';

export type SendInvitationRequestBody = {
projectID: string;
role: 'Editor' | 'Owner' | 'Viewer';
role: 'Executor' | 'Owner' | 'Viewer';
userID: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { ProjectMember } from '../schemas/ProjectMember';

export interface GetInvitationResponse {
invitationRole: 'Editor' | 'Owner' | 'Viewer';
invitationRole: 'Executor' | 'Owner' | 'Viewer';
projectID: string;
projectName: string;
projectOwner: ProjectMember;
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/api/auth/schemas/ProjectMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ProjectMember {
invitation: 'Accepted' | 'Declined' | 'Exited' | 'Pending';
joinedAt?: string;
name?: string;
role: 'Editor' | 'Owner' | 'Viewer';
role: 'Executor' | 'Owner' | 'Viewer';
userID: string;
username: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const RunExperimentButton = ({
icon={'play'}
withoutCurrentColor
variation={ButtonVariation.ICON}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
onClick={() => {
runChaosExperimentMutation({
variables: { projectID: scope.projectID, experimentID: experimentID }
Expand Down Expand Up @@ -161,7 +161,7 @@ export const StopExperimentButton = ({
isDark: true,
...tooltipProps
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
variation={ButtonVariation.ICON}
icon={'stop'}
onClick={openStopExperimentDialog}
Expand Down Expand Up @@ -240,7 +240,7 @@ export const StopExperimentRunButton = ({
}}
variation={ButtonVariation.ICON}
icon={'stop'}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
onClick={openStopExperimentRunDialog}
/>
</div>
Expand Down Expand Up @@ -271,7 +271,7 @@ export const EditExperimentButton = ({ experimentID, tooltipProps }: ActionButto
search: `tab=${StudioTabs.BUILDER}`
});
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
/>
</div>
);
Expand All @@ -297,7 +297,7 @@ export const CloneExperimentButton = ({ experimentID, tooltipProps }: ActionButt
pathname: paths.toCloneExperiment({ experimentKey: experimentID })
});
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
/>
</div>
);
Expand Down Expand Up @@ -425,7 +425,7 @@ export const EnableDisableCronButton = ({
variation={ButtonVariation.ICON}
icon={'time'}
onClick={openCronEnableDisableDialog}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
/>
</div>
{cronEnableDisableDialog}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function NewExperimentButton({ disabled }: { disabled?: boolean }
<ParentComponentErrorWrapper>
<RbacButton
disabled={disabled}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
variation={ButtonVariation.PRIMARY}
text={getString('newExperiment')}
icon="plus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function PredefinedExperimentCard({ predefinedExperiment }: PredefinedExperiment
variation={ButtonVariation.PRIMARY}
icon="play"
text={getString('launchExperiment')}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
onClick={e => {
e.stopPropagation(); // Prevents the card from being clicked
launchExperiment();
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/models/rbac.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum PermissionGroup {
OWNER = 'Owner',
EDITOR = 'Editor',
Executor = 'Executor',
VIEWER = 'Viewer'
}

Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/strings/strings.en.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
404Error: Oops, we could not find this page.
Executor: Executor
FRI: FRI
MON: MON
NASlash: N/A
Expand Down Expand Up @@ -306,7 +307,6 @@ editSameExperimentDescription: >-
editSameExperimentTitle: Edit on the existing Experiment
editYaml: Edit Yaml
editingChaosHub: Editing ChaosHub
editor: Editor
effect: Effect
email: Email
emailIsRequired: Email is a required field
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/strings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type PrimitiveObject<T extends string> = Record<T, string | number | bool

export interface StringsMap {
'404Error': unknown
'Executor': unknown
'FRI': unknown
'MON': unknown
'NASlash': unknown
Expand Down Expand Up @@ -259,7 +260,6 @@ export interface StringsMap {
'editSameExperimentTitle': unknown
'editYaml': unknown
'editingChaosHub': unknown
'editor': unknown
'effect': unknown
'email': unknown
'emailIsRequired': unknown
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/utils/getPropsBasedOnStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function getPropsBasedOnPermissionGroup(status: Status): StatusProps {
color: Color.GREEN_800,
bgColor: `var(--green-50)`
};
case PermissionGroup.EDITOR:
case PermissionGroup.Executor:
return {
color: Color.ORANGE_700,
bgColor: `var(--orange-50)`
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/web/src/utils/usePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function usePermissions(props: UserPermissionsProps): boolean {
if (projectRole) {
if (projectRole === PermissionGroup.OWNER) {
return false;
} else if (projectRole === PermissionGroup.EDITOR) {
if (permission === PermissionGroup.EDITOR || permission === PermissionGroup.VIEWER) {
} else if (projectRole === PermissionGroup.Executor) {
if (permission === PermissionGroup.Executor || permission === PermissionGroup.VIEWER) {
return false;
}
} else if (projectRole === PermissionGroup.VIEWER) {
Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/web/src/views/ChaosHubMenu/ChaosHubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const ChaosHubMenuView: React.FC<ChaosHubMenuViewProps> = ({
hubID.current = chaosHub.id;
syncChaosHubMutation({ variables: { projectID: scope.projectID, id: chaosHub.id } });
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.Executor}
/>
)}
<ParentComponentErrorWrapper>
Expand Down Expand Up @@ -125,7 +125,7 @@ export const ChaosHubMenuView: React.FC<ChaosHubMenuViewProps> = ({
setSelectedHubDetails(chaosHub);
setEditHubModal(true);
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
/>
</ParentComponentErrorWrapper>
)}
Expand All @@ -139,7 +139,7 @@ export const ChaosHubMenuView: React.FC<ChaosHubMenuViewProps> = ({
onClick={() => {
deleteChaosHubMutation({ variables: { projectID: scope.projectID, hubID: chaosHub.id } });
}}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
/>
</ParentComponentErrorWrapper>
)}
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function AddHubModal({ listChaosHubRefetch, disabled }: AddHubModalProviderProps
icon="plus"
onClick={() => open()}
disabled={disabled}
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
/>
{isOpen && (
<Dialog isOpen={isOpen} enforceFocus={false} onClose={() => close()} className={css.modalWithHelpPanel}>
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/views/ChaosProbe/ChaosProbeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function ChaosProbeHeader({
text={getString('editProbe')}
variation={ButtonVariation.SECONDARY}
icon="Edit"
permission={PermissionGroup.EDITOR}
permission={PermissionGroup.OWNER}
onClick={setEditProbeOpen}
/>
</Layout.Horizontal>
Expand Down
Loading

0 comments on commit 9efc00c

Please sign in to comment.