mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: additional bugs
This commit is contained in:
parent
0c6ce121b0
commit
925276dc7a
3 changed files with 16 additions and 10 deletions
|
|
@ -8,7 +8,7 @@ import { revalidateTags } from "@services/utils/ts/requests";
|
||||||
import ActivityIndicators from "@components/Pages/Courses/ActivityIndicators";
|
import ActivityIndicators from "@components/Pages/Courses/ActivityIndicators";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import GeneralWrapperStyled from "@components/StyledElements/Wrappers/GeneralWrapper";
|
import GeneralWrapperStyled from "@components/StyledElements/Wrappers/GeneralWrapper";
|
||||||
import { getCourseThumbnailMediaDirectory } from "@services/media/media";
|
import { getCourseThumbnailMediaDirectory, getUserAvatarMediaDirectory } from "@services/media/media";
|
||||||
import { ArrowRight, Check, File, Sparkles, Star, Video } from "lucide-react";
|
import { ArrowRight, Check, File, Sparkles, Star, Video } from "lucide-react";
|
||||||
import Avvvatars from "avvvatars-react";
|
import Avvvatars from "avvvatars-react";
|
||||||
import { getUser } from "@services/users/users";
|
import { getUser } from "@services/users/users";
|
||||||
|
|
@ -193,7 +193,7 @@ const CourseClient = (props: any) => {
|
||||||
<div className="course_metadata_right space-y-3 w-72 antialiased flex flex-col ml-10 h-fit p-3 py-5 bg-white shadow-md shadow-gray-300/25 outline outline-1 outline-neutral-200/40 rounded-lg overflow-hidden">
|
<div className="course_metadata_right space-y-3 w-72 antialiased flex flex-col ml-10 h-fit p-3 py-5 bg-white shadow-md shadow-gray-300/25 outline outline-1 outline-neutral-200/40 rounded-lg overflow-hidden">
|
||||||
{user &&
|
{user &&
|
||||||
<div className="flex flex-col mx-auto space-y-3 px-2 py-2 items-center">
|
<div className="flex flex-col mx-auto space-y-3 px-2 py-2 items-center">
|
||||||
<UserAvatar border="border-8" avatar_url={course.authors[0].avatar_url} width={100} />
|
<UserAvatar border="border-8" avatar_url={getUserAvatarMediaDirectory(course.authors[0].user_uuid,course.authors[0].avatar_image)} width={100} />
|
||||||
<div className="-space-y-2 ">
|
<div className="-space-y-2 ">
|
||||||
<div className="text-[12px] text-neutral-400 font-semibold">Author</div>
|
<div className="text-[12px] text-neutral-400 font-semibold">Author</div>
|
||||||
<div className="text-xl font-bold text-neutral-800">
|
<div className="text-xl font-bold text-neutral-800">
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ function UserAvatar(props: UserAvatarProps) {
|
||||||
return predefinedAvatar
|
return predefinedAvatar
|
||||||
} else {
|
} else {
|
||||||
if (props.avatar_url) {
|
if (props.avatar_url) {
|
||||||
|
console.log('avatar_url',props.avatar_url)
|
||||||
return props.avatar_url
|
return props.avatar_url
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,18 @@ export const AuthenticatedClientElement = (props: AuthenticatedClientElementProp
|
||||||
const [isAllowed, setIsAllowed] = React.useState(false);
|
const [isAllowed, setIsAllowed] = React.useState(false);
|
||||||
const session = useSession() as any;
|
const session = useSession() as any;
|
||||||
const org = useOrg() as any;
|
const org = useOrg() as any;
|
||||||
|
|
||||||
|
|
||||||
function isUserAllowed(roles: any[], action: string, resourceType: string, org_uuid: string): boolean {
|
function isUserAllowed(roles: any[], action: string, resourceType: string, org_uuid: string): boolean {
|
||||||
// Iterate over the user's roles
|
// Iterate over the user's roles
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
|
|
||||||
// Check if the role is for the right organization
|
// Check if the role is for the right organization
|
||||||
if (role.org.org_uuid === org_uuid) {
|
if (role.org.org_uuid === org_uuid) {
|
||||||
// Check if the user has the role for the resource type
|
// Check if the user has the role for the resource type
|
||||||
if (role.role.rights && role.role.rights[resourceType]) {
|
if (role.role.rights && role.role.rights[resourceType]) {
|
||||||
|
|
||||||
|
|
||||||
// Check if the user is allowed to execute the action
|
// Check if the user is allowed to execute the action
|
||||||
const actionKey = `action_${action}`;
|
const actionKey = `action_${action}`;
|
||||||
if (role.role.rights[resourceType][actionKey] === true) {
|
if (role.role.rights[resourceType][actionKey] === true) {
|
||||||
|
|
@ -43,11 +43,16 @@ export const AuthenticatedClientElement = (props: AuthenticatedClientElementProp
|
||||||
}
|
}
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
|
if (session.isAuthenticated === false) {
|
||||||
if (props.checkMethod === 'authentication') {
|
setIsAllowed(false);
|
||||||
setIsAllowed(session.isAuthenticated);
|
return;
|
||||||
} else if (props.checkMethod === 'roles') {
|
}
|
||||||
return setIsAllowed(isUserAllowed(session.roles, props.action!, props.ressourceType!, org.org_uuid));
|
else {
|
||||||
|
if (props.checkMethod === 'authentication') {
|
||||||
|
setIsAllowed(session.isAuthenticated);
|
||||||
|
} else if (props.checkMethod === 'roles') {
|
||||||
|
return setIsAllowed(isUserAllowed(session.roles, props.action!, props.ressourceType!, org.org_uuid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue