Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Siddev3 #427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 14 additions & 10 deletions packages/alea-frontend/pages/acl/[aclId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
Tooltip,
Typography,
} from '@mui/material';
import { getAcl, getAllAclMembers, isMember, isUserMember } from '@stex-react/api';
import {
getAcl,
getAclUserDetails,
getAllAclMembers,
isMember,
isUserMember,
} from '@stex-react/api';
import { NextPage } from 'next';
import Link from 'next/link';
import { useRouter } from 'next/router';
Expand All @@ -23,7 +29,7 @@ const AclId: NextPage = () => {
const aclId = router.query.aclId as string;

const [acls, setAcls] = useState<string[]>([]);
const [allMemberUserIds, setAllMemberUserIds] = useState<string[]>([]);
const [directMembersNamesAndIds, setDirectMembersNamesAndIds] = useState([]);
const [desc, setDesc] = useState<string>(null);
const [isOpen, setIsOpen] = useState<boolean>(false);
const [updaterACLId, setUpdaterACLId] = useState<string>(null);
Expand All @@ -41,11 +47,9 @@ const AclId: NextPage = () => {
setUpdaterACLId(acl?.updaterACLId);
setIsOpen(acl?.isOpen);
const aclIds = new Set<string>();
const userMembers = new Set<string>();

const aclUserDetails = await getAclUserDetails(aclId);
acl.memberACLIds.forEach((m) => aclIds.add(m));
acl.memberUserIds.forEach((m) => userMembers.add(m));
setAllMemberUserIds(Array.from(userMembers));
setDirectMembersNamesAndIds(aclUserDetails);
setAcls(Array.from(aclIds));
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -215,13 +219,13 @@ const AclId: NextPage = () => {
</Box>
)}

{allMemberUserIds.length !== 0 && (
{directMembersNamesAndIds.length !== 0 && (
<Box sx={{ marginTop: '32px' }}>
<Typography variant="h6" color="secondary">
Direct Members
</Typography>
<List>
{allMemberUserIds.map((user, index) => (
{directMembersNamesAndIds.map((user, index) => (
<React.Fragment key={user}>
<ListItem
button
Expand All @@ -232,9 +236,9 @@ const AclId: NextPage = () => {
},
}}
>
<ListItemText primary={user} />
<ListItemText primary={`${user.fullName} (${user.userId})`} />
</ListItem>
{index < allMemberUserIds.length - 1 && <Divider />}
{index < directMembersNamesAndIds.length - 1 && <Divider />}
</React.Fragment>
))}
</List>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { AccessControlList } from '@stex-react/api';
import { NextApiRequest, NextApiResponse } from 'next';
import { executeAndEndSet500OnError, executeDontEndSet500OnError } from '../comment-utils';
import { ACLMembership } from './acl-membership';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const id = req.query.id as string;
if (!id) return res.status(422).send(`Missing param id.`);
const acls: any[] = await executeAndEndSet500OnError(
`SELECT * FROM AccessControlList where id = ?`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't select *, select id is sufficient

[id],
res
);
const dbAcl = acls?.[0];
if (!dbAcl) return res.status(404).send(`No ACL with id [${id}].`);
Comment on lines +14 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const dbAcl = acls?.[0];
if (!dbAcl) return res.status(404).send(`No ACL with id [${id}].`);
if (!acls?.[0]) return res.status(404).send(`No ACL with id [${id}].`);


const members: ACLMembership[] = await executeAndEndSet500OnError(
'SELECT * FROM ACLMembership WHERE parentACLId = ?',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'SELECT * FROM ACLMembership WHERE parentACLId = ?',
'SELECT memberUserId FROM ACLMembership WHERE parentACLId = ? AND memberUserId IS NOT NULL',

[id],
res
);
const directMembers = members.map((m) => m.memberUserId).filter((u) => u);
if (directMembers.length === 0) {
return res.status(200).send([]);
}
const result: { firstname: string; lastname: string; userId: string }[] =
await executeDontEndSet500OnError(
`select firstname, lastname, userId from userInfo where userId IN (?)`,
[directMembers],
res
);
res
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to also return the members whose entry is not found the database. Return empty string from this API.
And on the frontend show Unknown (in italics)

.status(200)
.send(result.map((c) => ({ fullName: `${c.firstname} ${c.lastname}`, userId: `${c.userId}` })));
}
5 changes: 5 additions & 0 deletions packages/api/src/lib/access-control-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export async function getAcl(aclId: string): Promise<AccessControlList> {
return resp.data as AccessControlList;
}

export async function getAclUserDetails(aclId : string):Promise<{fullName: string, userid:string}[]>{
const resp = await axios.get(`/api/access-control/get-acl-userdetails?id=${aclId}`);
return resp.data as {fullName: string,userid:string}[]
}

export async function getCourseAcls(courseId: string, instanceId: string) {
const resp = await axios.get(
`/api/access-control/get-course-acls?courseId=${courseId}&instanceId=${instanceId}`
Expand Down