Skip to content

Commit

Permalink
fix: #13735 task assignee should be entity owner if present (#14203)
Browse files Browse the repository at this point in the history
* fix: #13735 task assignee should be entity owner if present

* added e2e tests for the same

* do not allow edit asignee in case of entity has owner
  • Loading branch information
chirag-madlani authored Dec 4, 2023
1 parent 597c499 commit 7b2206c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
35 changes: 22 additions & 13 deletions openmetadata-ui/src/main/resources/ui/cypress/common/TaskUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,35 @@ export const editAssignee = () => {
cy.get(`[data-testid="assignee-${assignee}"]`).should('be.visible');
};

export const createDescriptionTask = (value) => {
export const createDescriptionTask = (value, assigneeDisabled) => {
interceptURL('POST', 'api/v1/feed', 'createTask');

cy.get('#title').should(
'have.value',
`Update description for table ${value.term}`
);

cy.get('[data-testid="select-assignee"] > .ant-select-selector').type(
value.assignee ?? assignee
);
// select value from dropdown
verifyResponseStatusCode('@suggestApi', 200);

cy.get(`[data-testid="assignee-option-${value.assignee ?? assignee}"]`)
.should('be.visible')
.trigger('mouseover')
.trigger('click');

cy.clickOutside();
if (assigneeDisabled) {
cy.get('[data-testid="select-assignee"] > .ant-select-selector').contains(
value.assignee
);

cy.get(
'[data-testid="select-assignee"] > .ant-select-selector input'
).should('be.disabled');
} else {
cy.get('[data-testid="select-assignee"] > .ant-select-selector').type(
value.assignee ?? assignee
);
// select value from dropdown
verifyResponseStatusCode('@suggestApi', 200);

cy.get(`[data-testid="assignee-option-${value.assignee ?? assignee}"]`)
.should('be.visible')
.trigger('mouseover')
.trigger('click');
cy.clickOutside();
}

cy.get(descriptionBox).scrollIntoView().clear().type('Updated description');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// <reference types="cypress" />

import {
addOwner,
interceptURL,
toastNotification,
verifyResponseStatusCode,
Expand All @@ -22,6 +23,7 @@ import {
import { createEntityTable, hardDeleteService } from '../../common/EntityUtils';
import {
createAndUpdateDescriptionTask,
createDescriptionTask,
editAssignee,
verifyTaskDetails,
} from '../../common/TaskUtils';
Expand Down Expand Up @@ -193,4 +195,38 @@ describe('Task flow should work', () => {
});
});
});

it('Asignee field should be disabled for owned entity tasks', () => {
interceptURL(
'GET',
`/api/v1/${ENTITY_TABLE.entity}/name/*`,
'getEntityDetails'
);

visitEntityDetailsPage({
term: ENTITY_TABLE.term,
serviceName: ENTITY_TABLE.serviceName,
entity: ENTITY_TABLE.entity,
});

addOwner('Adam Rodriguez', 'tables');

cy.get('[data-testid="request-description"]').click();

cy.wait('@getEntityDetails').then((res) => {
const entity = res.response.body;

// create description task and verify asignee field to have owner
// and should be disbaled

createDescriptionTask(
{
...ENTITY_TABLE,
assignee: 'Adam Rodriguez',
term: entity.displayName ?? entity.name,
},
true
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ export const TaskTab = ({
}}
onSave={() => assigneesForm.submit()}>
<Assignees
disabled={Boolean(owner)}
options={options}
value={updatedAssignees}
onChange={(values) =>
Expand All @@ -490,7 +491,7 @@ export const TaskTab = ({
profileWidth="24"
showUserName={false}
/>
{(isCreator || hasEditAccess) && !isTaskClosed ? (
{(isCreator || hasEditAccess) && !isTaskClosed && !owner ? (
<Button
className="flex-center p-0"
data-testid="edit-assignees"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const RequestDescription = () => {
},
]}>
<Assignees
disabled={Boolean(entityData.owner)}
options={options}
value={assignees}
onChange={setAssignees}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const RequestTag = () => {
},
]}>
<Assignees
disabled={Boolean(entityData.owner)}
options={options}
value={assignees}
onChange={setAssignees}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const UpdateDescription = () => {
},
]}>
<Assignees
disabled={Boolean(entityData.owner)}
options={options}
value={assignees}
onChange={setAssignees}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const UpdateTag = () => {
},
]}>
<Assignees
disabled={Boolean(entityData.owner)}
options={options}
value={assignees}
onChange={setAssignees}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ interface Props {
value: Option[];
onSearch: (value: string) => void;
onChange: (values: Option[]) => void;
disabled?: boolean;
}

const Assignees: FC<Props> = ({
value: assignees = [],
onSearch,
onChange,
options,
disabled,
}) => {
const handleOnChange = (_values: Option[], newOptions: Option | Option[]) => {
const newValues = (newOptions as Option[]).map((option) => ({
Expand Down Expand Up @@ -94,6 +96,7 @@ const Assignees: FC<Props> = ({
className="ant-select-custom select-assignee"
data-testid="select-assignee"
defaultActiveFirstOption={false}
disabled={disabled}
filterOption={false}
mode="multiple"
notFoundContent={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const UserPage = () => {
if (userData.id === currentUser?.id) {
updateCurrentUser(response);
}
setUserData(response);
setUserData((prev) => ({ ...prev, ...response }));
} else {
throw t('message.unexpected-error');
}
Expand Down

0 comments on commit 7b2206c

Please sign in to comment.