Skip to content

Commit

Permalink
EPMRPP-91885 || Admin not assigned to a project can not open the proj…
Browse files Browse the repository at this point in the history
…ect, wrong project name is displayed in the url
  • Loading branch information
BlazarQSO committed Jun 19, 2024
1 parent 4aa2991 commit 3f7a47f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/controllers/administrate/projects/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ function* watchDeleteProject() {

function* navigateToProject({ payload }) {
const { project } = payload;
const { organizationSlug, projectSlug } = project;
const { organizationSlug, projectSlug, projectKey } = project;

yield put({
type: PROJECT_PAGE,
payload: { organizationSlug, projectSlug },
payload: { organizationSlug, projectSlug, projectKey },
});
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/controllers/initialData/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ import {
} from 'controllers/plugins';
import { getStorageItem } from 'common/utils';
import { SET_ACTIVE_PROJECT_KEY } from 'controllers/user/constants';
import { fetchOrganizationsAction } from 'controllers/organizations';
import { setInitialDataReadyAction } from './actionCreators';
import { FETCH_INITIAL_DATA } from './constants';

function* fetchInitialData() {
yield put(setTokenAction(getStorageItem(TOKEN_KEY) || DEFAULT_TOKEN));
yield put(fetchAppInfoAction());
yield put(fetchUserAction());
yield put(fetchOrganizationsAction());
const userResult = yield take([FETCH_USER_SUCCESS, FETCH_USER_ERROR]);
if (!userResult.error) {
const { payload: activeProjectKey } = yield take(SET_ACTIVE_PROJECT_KEY);
Expand Down
14 changes: 12 additions & 2 deletions app/src/controllers/project/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import { createSelector } from 'reselect';
import { OWNER } from 'common/constants/permissions';
import { DEFECT_TYPES_SEQUENCE } from 'common/constants/defectTypes';
import { assignedOrganizationsSelector } from 'controllers/user';
import { assignedOrganizationsSelector, userAccountRoleSelector } from 'controllers/user';
import { organizationsListSelector } from 'controllers/organizations';
import { ADMINISTRATOR } from 'common/constants/accountRoles';
import {
ANALYZER_ATTRIBUTE_PREFIX,
JOB_ATTRIBUTE_PREFIX,
Expand Down Expand Up @@ -55,7 +57,15 @@ export const projectNameSelector = (state) => projectInfoSelector(state).project
export const organizationNameSelector = createSelector(
assignedOrganizationsSelector,
projectInfoSelector,
(assignedOrganizations, { organizationId }) => {
userAccountRoleSelector,
organizationsListSelector,
(assignedOrganizations, { organizationId }, accountRole, organizations) => {
const isAdmin = accountRole === ADMINISTRATOR;

if (isAdmin) {
return organizations.find(({ id }) => id === organizationId)?.name;
}

const assignedOrganizationKey = Object.keys(assignedOrganizations).find(
(assignedOrganization) =>
assignedOrganizations[assignedOrganization].organizationId === organizationId,
Expand Down
14 changes: 10 additions & 4 deletions app/src/routes/routesMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,13 @@ const routesMap = {
export const onBeforeRouteChange = (dispatch, getState, { action }) => {
const {
type: nextPageType,
payload: { organizationSlug: hashOrganizationSlug, projectSlug: hashProjectSlug },
payload: {
organizationSlug: hashOrganizationSlug,
projectSlug: hashProjectSlug,
projectKey: hashProjectKey,
},
} = action;

let { organizationSlug, projectSlug } = activeProjectSelector(getState());
const currentPageType = pageSelector(getState());
const authorized = isAuthorizedSelector(getState());
Expand All @@ -334,12 +339,13 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
const isAdmin = accountRole === ADMINISTRATOR;
const isAdminNewPageType = !!adminPageNames[nextPageType];
const isAdminCurrentPageType = !!adminPageNames[currentPageType];
const projectKey = assignedProjects?.[hashProjectSlug]?.projectKey;
const projectKey =
isAdmin && hashProjectKey ? hashProjectKey : assignedProjects?.[hashProjectSlug]?.projectKey;
const isProjectExists =
assignedOrganizations &&
hashOrganizationSlug in assignedOrganizations &&
(isAdmin || hashOrganizationSlug in assignedOrganizations) &&
assignedProjects &&
hashProjectSlug in assignedProjects;
(isAdmin || hashProjectSlug in assignedProjects);
const isChangedProject =
organizationSlug !== hashOrganizationSlug || projectSlug !== hashProjectSlug;

Expand Down

0 comments on commit 3f7a47f

Please sign in to comment.