Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useEffect, useState } from 'react';
import type { ElementLike } from 'diagram-js/lib/core/Types';
import { Divider, Space, Tooltip, Button, Cascader } from 'antd';
import { Divider, Space, Tooltip, Button, Cascader, Tag, Select } from 'antd';
import { UserOutlined, TeamOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { BPMNCanvasRef } from '@/components/bpmn-canvas';
import type { CascaderProps, GetProp } from 'antd';
Expand Down Expand Up @@ -105,6 +105,23 @@ function updateResource(
}
}

const customTagRender: React.ComponentProps<typeof Cascader>['tagRender'] = ({
label,
value,
...rest
}) => {
if (value === 'all-user') {
label = 'All Users';
} else if (value === 'all-roles') {
label = 'All Roles';
}
return (
<Tag style={{ marginRight: '5px', backgroundColor: 'rgb(0, 0, 0, 0.06)' }} {...rest}>
{label}
</Tag>
);
};

const filter = (inputValue: string, path: DefaultOptionType[]) =>
path.some((option) => `${option?.value}`.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);

Expand Down Expand Up @@ -165,6 +182,7 @@ export const PotentialOwner: FC<PotentialOwnerProps> = ({
placeholder="Select User or Roles that can claim this task"
style={{ width: '100%' }}
multiple
tagRender={customTagRender}
showSearch={{ filter }}
// @ts-ignore
onChange={setPotentialOwner}
Expand Down Expand Up @@ -243,6 +261,7 @@ export const ResponsibleParty: FC<ResponsibilityProps> = ({
placeholder="Select User or Roles responsible"
style={{ width: '100%' }}
multiple
tagRender={customTagRender}
showSearch={{ filter }}
// @ts-ignore
onChange={setResponsible}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { getCurrentEnvironment, getCurrentUser } from '@/components/auth';
import { getRolesWithMembers } from '@/lib/data/db/iam/roles';
import { RoleType, UserType } from './use-potentialOwner-store';
import { getSpaceUsers } from '@/lib/data/users';
import { isUserErrorResponse } from '@/lib/user-error';

export const fetchPotentialOwner = async (environmentId: string) => {
const user: UserType = {};
Expand All @@ -12,16 +14,19 @@ export const fetchPotentialOwner = async (environmentId: string) => {

if (activeEnvironment.isOrganization) {
const rawRoles = await getRolesWithMembers(activeEnvironment.spaceId, ability);
const users = await getSpaceUsers(activeEnvironment.spaceId);

rawRoles.forEach((role) => {
roles[role.id] = role.name;

role.members.forEach((member) => {
user[member.id] = {
userName: member.username,
name: member.firstName + ' ' + member.lastName,
if (!isUserErrorResponse(users)) {
users.forEach((u) => {
user[u.id] = {
userName: u.username || undefined,
name: (u.firstName + ' ' + u.lastName).trim(),
};
});
}

rawRoles.forEach((role) => {
roles[role.id] = role.name;
});
} else {
// make sure to get the current user that might not be assigned to any role
Expand Down
18 changes: 0 additions & 18 deletions src/management-system-v2/lib/data/db/iam/memberships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,6 @@ export async function getFullMembersWithRoles(environmentId: string, ability?: A
/**
* Returns the users that exist in a specific space
*/
export async function getUsersInSpace(spaceId: string, ability?: Ability) {
//TODO: ability check
if (ability) ability;

const users = await db.user.findMany({
where: {
memberIn: {
some: {
space: {
id: spaceId,
},
},
},
},
});

return users;
}

export async function isMember(
environmentId: string,
Expand Down
13 changes: 12 additions & 1 deletion src/management-system-v2/lib/data/users.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use server';

import { getCurrentEnvironment, getCurrentUser } from '@/components/auth';
import { UserErrorType, getErrorMessage, userError } from '../user-error';
import { UserErrorType, getErrorMessage, permissionDenied, userError } from '../user-error';
import { AuthenticatedUserData, AuthenticatedUserDataSchema } from './user-schema';
import { ReactNode } from 'react';
import { OrganizationEnvironment } from './environment-schema';
Expand All @@ -12,6 +12,7 @@ import {
updateUser as _updateUser,
setUserPassword as _setUserPassword,
getUserById,
getSpaceUsers as _getSpaceUsers,
} from '@/lib/data/db/iam/users';
import { revalidatePath } from 'next/cache';
import { getEnvironmentById } from './db/iam/environments';
Expand All @@ -20,6 +21,16 @@ import { getAppliedRolesForUser } from '../authorization/organizationEnvironment
import db from '@/lib/data/db/index';
import { env } from '../ms-config/env-vars';

export async function getSpaceUsers(spaceId: string) {
const { ability, activeEnvironment } = await getCurrentEnvironment(spaceId);

if (!ability.can('view', 'User')) return permissionDenied();

const users = await _getSpaceUsers(spaceId, activeEnvironment.isOrganization);

return ability.filter('view', 'User', users);
}

export async function deleteUser() {
const { userId } = await getCurrentUser();

Expand Down
Loading