mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: forward org_id values for lectures
This commit is contained in:
parent
98b470f2ab
commit
447ac93649
6 changed files with 75 additions and 67 deletions
|
|
@ -13,6 +13,7 @@ import { useRouter } from "next/navigation";
|
||||||
import NewChapterModal from "@components/Modals/CourseEdit/NewChapter";
|
import NewChapterModal from "@components/Modals/CourseEdit/NewChapter";
|
||||||
import NewLectureModal from "@components/Modals/CourseEdit/NewLecture";
|
import NewLectureModal from "@components/Modals/CourseEdit/NewLecture";
|
||||||
import { createLecture, createFileLecture } from "@services/courses/lectures";
|
import { createLecture, createFileLecture } from "@services/courses/lectures";
|
||||||
|
import { getOrganizationContextInfo } from "@services/orgs";
|
||||||
|
|
||||||
function CourseEdit(params: any) {
|
function CourseEdit(params: any) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -31,6 +32,8 @@ function CourseEdit(params: any) {
|
||||||
const courseid = params.params.courseid;
|
const courseid = params.params.courseid;
|
||||||
const orgslug = params.params.orgslug;
|
const orgslug = params.params.orgslug;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function getCourseChapters() {
|
async function getCourseChapters() {
|
||||||
const courseChapters = await getCourseChaptersMetadata(courseid);
|
const courseChapters = await getCourseChaptersMetadata(courseid);
|
||||||
setData(courseChapters);
|
setData(courseChapters);
|
||||||
|
|
@ -75,8 +78,9 @@ function CourseEdit(params: any) {
|
||||||
// Submit new lecture
|
// Submit new lecture
|
||||||
const submitLecture = async (lecture: any) => {
|
const submitLecture = async (lecture: any) => {
|
||||||
console.log("submitLecture", lecture);
|
console.log("submitLecture", lecture);
|
||||||
|
let org = await getOrganizationContextInfo(orgslug);
|
||||||
await updateChaptersMetadata(courseid, data);
|
await updateChaptersMetadata(courseid, data);
|
||||||
await createLecture(lecture, lecture.chapterId);
|
await createLecture(lecture, lecture.chapterId, org.org_id);
|
||||||
await getCourseChapters();
|
await getCourseChapters();
|
||||||
setNewLectureModal(false);
|
setNewLectureModal(false);
|
||||||
};
|
};
|
||||||
|
|
@ -226,63 +230,63 @@ function CourseEdit(params: any) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Page>
|
<Page>
|
||||||
<Title>
|
<Title>
|
||||||
Edit Course {" "}
|
Edit Course {" "}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setNewChapterModal(true);
|
setNewChapterModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Add chapter +
|
Add chapter +
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateChapters();
|
updateChapters();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
</Title>
|
</Title>
|
||||||
{newChapterModal && <NewChapterModal closeModal={closeNewChapterModal} submitChapter={submitChapter}></NewChapterModal>}
|
{newChapterModal && <NewChapterModal closeModal={closeNewChapterModal} submitChapter={submitChapter}></NewChapterModal>}
|
||||||
{newLectureModal && (
|
{newLectureModal && (
|
||||||
<NewLectureModal
|
<NewLectureModal
|
||||||
closeModal={closeNewLectureModal}
|
closeModal={closeNewLectureModal}
|
||||||
submitFileLecture={submitFileLecture}
|
submitFileLecture={submitFileLecture}
|
||||||
submitLecture={submitLecture}
|
submitLecture={submitLecture}
|
||||||
chapterId={newLectureModalData}
|
chapterId={newLectureModalData}
|
||||||
></NewLectureModal>
|
></NewLectureModal>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
{winReady && (
|
{winReady && (
|
||||||
<ChapterlistWrapper>
|
<ChapterlistWrapper>
|
||||||
<DragDropContext onDragEnd={onDragEnd}>
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
<Droppable key="chapters" droppableId="chapters" type="chapter">
|
<Droppable key="chapters" droppableId="chapters" type="chapter">
|
||||||
{(provided) => (
|
{(provided) => (
|
||||||
<>
|
<>
|
||||||
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
|
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
|
||||||
{getChapters().map((info: any, index: any) => (
|
{getChapters().map((info: any, index: any) => (
|
||||||
<>
|
<>
|
||||||
<Chapter
|
<Chapter
|
||||||
orgslug={orgslug}
|
orgslug={orgslug}
|
||||||
courseid={courseid}
|
courseid={courseid}
|
||||||
openNewLectureModal={openNewLectureModal}
|
openNewLectureModal={openNewLectureModal}
|
||||||
deleteChapter={deleteChapterUI}
|
deleteChapter={deleteChapterUI}
|
||||||
key={index}
|
key={index}
|
||||||
info={info}
|
info={info}
|
||||||
index={index}
|
index={index}
|
||||||
></Chapter>
|
></Chapter>
|
||||||
</>
|
</>
|
||||||
))}
|
))}
|
||||||
{provided.placeholder}
|
{provided.placeholder}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Droppable>
|
</Droppable>
|
||||||
</DragDropContext>
|
</DragDropContext>
|
||||||
</ChapterlistWrapper>
|
</ChapterlistWrapper>
|
||||||
)}
|
)}
|
||||||
</Page>
|
</Page>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import Layout from "@components/UI/Layout";
|
||||||
import { Title } from "@components/UI/Elements/Styles/Title";
|
import { Title } from "@components/UI/Elements/Styles/Title";
|
||||||
import { createNewCourse } from "@services/courses/courses";
|
import { createNewCourse } from "@services/courses/courses";
|
||||||
import { getOrganizationContextInfo } from "@services/orgs";
|
import { getOrganizationContextInfo } from "@services/orgs";
|
||||||
|
import { getUriWithOrg } from "@services/config";
|
||||||
|
|
||||||
const NewCoursePage = (params: any) => {
|
const NewCoursePage = (params: any) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -40,7 +41,7 @@ const NewCoursePage = (params: any) => {
|
||||||
|
|
||||||
// TODO : wow this is terrible - fix this
|
// TODO : wow this is terrible - fix this
|
||||||
if (status.org_id == orgId) {
|
if (status.org_id == orgId) {
|
||||||
router.push(`/org/${orgslug}/courses`);
|
router.push(getUriWithOrg(orgslug, `/courses`));
|
||||||
} else {
|
} else {
|
||||||
alert("Error creating course, please see console logs");
|
alert("Error creating course, please see console logs");
|
||||||
console.log(status);
|
console.log(status);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { getAPIUrl } from "@services/config";
|
import { getAPIUrl } from "@services/config";
|
||||||
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
|
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
|
||||||
|
|
||||||
export async function createLecture(data: any, chapter_id: any) {
|
export async function createLecture(data: any, chapter_id: any, org_id: any) {
|
||||||
data.content = {};
|
data.content = {};
|
||||||
|
|
||||||
// remove chapter_id from data
|
// remove chapter_id from data
|
||||||
delete data.chapterId;
|
delete data.chapterId;
|
||||||
|
|
||||||
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}`, RequestBody("POST", data))
|
|
||||||
|
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data))
|
||||||
.then((result) => result.json())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ async def api_create_lecture(request: Request, lecture_object: Lecture, org_id:
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{lecture_id}")
|
@router.get("/{lecture_id}")
|
||||||
async def api_get_lecture(request: Request, lecture_id: str, org_id: str, current_user: PublicUser = Depends(get_current_user)):
|
async def api_get_lecture(request: Request, lecture_id: str, current_user: PublicUser = Depends(get_current_user)):
|
||||||
"""
|
"""
|
||||||
Get single lecture by lecture_id
|
Get single lecture by lecture_id
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,13 @@ async def create_coursechapter(request: Request,coursechapter_object: CourseChap
|
||||||
coursechapters = request.app.db["coursechapters"]
|
coursechapters = request.app.db["coursechapters"]
|
||||||
courses = request.app.db["courses"]
|
courses = request.app.db["courses"]
|
||||||
|
|
||||||
|
# get course org_id and verify rights
|
||||||
|
course = await courses.find_one({"course_id": course_id})
|
||||||
|
|
||||||
# generate coursechapter_id with uuid4
|
# generate coursechapter_id with uuid4
|
||||||
coursechapter_id = str(f"coursechapter_{uuid4()}")
|
coursechapter_id = str(f"coursechapter_{uuid4()}")
|
||||||
|
|
||||||
hasRoleRights = await verify_user_rights_with_roles(request, "create", current_user.user_id, coursechapter_id)
|
hasRoleRights = await verify_user_rights_with_roles(request, "create", current_user.user_id, coursechapter_id, course["org_id"])
|
||||||
|
|
||||||
if not hasRoleRights:
|
if not hasRoleRights:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -229,7 +232,7 @@ async def verify_rights(request: Request,course_id: str, current_user: PublicUse
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_409_CONFLICT, detail=f"Course does not exist")
|
status_code=status.HTTP_409_CONFLICT, detail=f"Course does not exist")
|
||||||
|
|
||||||
hasRoleRights = await verify_user_rights_with_roles(request, action, current_user.user_id, course_id)
|
hasRoleRights = await verify_user_rights_with_roles(request, action, current_user.user_id, course_id, course["org_id"])
|
||||||
isAuthor = current_user.user_id in course["authors"]
|
isAuthor = current_user.user_id in course["authors"]
|
||||||
|
|
||||||
if not hasRoleRights and not isAuthor:
|
if not hasRoleRights and not isAuthor:
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ async def create_lecture(request: Request, lecture_object: Lecture, org_id: str,
|
||||||
|
|
||||||
# create lecture
|
# create lecture
|
||||||
lecture = LectureInDB(**lecture_object.dict(), creationDate=str(
|
lecture = LectureInDB(**lecture_object.dict(), creationDate=str(
|
||||||
datetime.now()), coursechapter_id=coursechapter_id, updateDate=str(datetime.now()), lecture_id=lecture_id)
|
datetime.now()), coursechapter_id=coursechapter_id, updateDate=str(datetime.now()), lecture_id=lecture_id, org_id=org_id)
|
||||||
await lectures.insert_one(lecture.dict())
|
await lectures.insert_one(lecture.dict())
|
||||||
|
|
||||||
# update chapter
|
# update chapter
|
||||||
|
|
@ -89,7 +89,7 @@ async def update_lecture(request: Request, lecture_object: Lecture, lecture_id:
|
||||||
datetime_object = datetime.now()
|
datetime_object = datetime.now()
|
||||||
|
|
||||||
updated_course = LectureInDB(
|
updated_course = LectureInDB(
|
||||||
lecture_id=lecture_id, coursechapter_id=lecture["coursechapter_id"], creationDate=creationDate, updateDate=str(datetime_object), **lecture_object.dict())
|
lecture_id=lecture_id, coursechapter_id=lecture["coursechapter_id"], creationDate=creationDate, updateDate=str(datetime_object), org_id=lecture["org_id"], **lecture_object.dict())
|
||||||
|
|
||||||
await lectures.update_one({"lecture_id": lecture_id}, {
|
await lectures.update_one({"lecture_id": lecture_id}, {
|
||||||
"$set": updated_course.dict()})
|
"$set": updated_course.dict()})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue