From 0e9bc615c93b7bb5e7e9fb0638b3896f66739ce7 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 18:47:25 +0100 Subject: [PATCH 01/11] chore: Added backlink to home page in header image --- web/components/Header.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/components/Header.tsx b/web/components/Header.tsx index 8d1bcaa..57efb57 100644 --- a/web/components/Header.tsx +++ b/web/components/Header.tsx @@ -7,6 +7,7 @@ import useApiServiceClient from "@/hooks/useApiServiceClient"; import { User } from "@/service/types/usernator"; import { useEffect } from "react"; import { publicRoutes } from "@/static/routes"; +import Link from "next/link"; const Header = () => { const api = useApiServiceClient(); @@ -32,13 +33,15 @@ const Header = () => {
- CompanyLogo - CompanyLogo + + CompanyLogo + CompanyLogo +
From b6d4af5b7fa8f7f669b7ffbbe0e177876ae7ad4b Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 18:55:05 +0100 Subject: [PATCH 02/11] feat: Added migration and model implementation for verified groups --- tasky/migrations/2024-11-18-175123_verified_groups/down.sql | 1 + tasky/migrations/2024-11-18-175123_verified_groups/up.sql | 1 + tasky/src/models/group.rs | 1 + tasky/src/response/group.rs | 4 ++++ tasky/src/schema.rs | 1 + 5 files changed, 8 insertions(+) create mode 100644 tasky/migrations/2024-11-18-175123_verified_groups/down.sql create mode 100644 tasky/migrations/2024-11-18-175123_verified_groups/up.sql diff --git a/tasky/migrations/2024-11-18-175123_verified_groups/down.sql b/tasky/migrations/2024-11-18-175123_verified_groups/down.sql new file mode 100644 index 0000000..aa88e5d --- /dev/null +++ b/tasky/migrations/2024-11-18-175123_verified_groups/down.sql @@ -0,0 +1 @@ +ALTER TABLE groups DROP COLUMN verified; diff --git a/tasky/migrations/2024-11-18-175123_verified_groups/up.sql b/tasky/migrations/2024-11-18-175123_verified_groups/up.sql new file mode 100644 index 0000000..719abde --- /dev/null +++ b/tasky/migrations/2024-11-18-175123_verified_groups/up.sql @@ -0,0 +1 @@ +ALTER TABLE groups ADD COLUMN verified BOOLEAN NOT NULL DEFAULT false; diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index 881ede6..27c4b3e 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -33,6 +33,7 @@ pub struct Group { pub join_policy: JoinRequestPolicy, pub created_at: NaiveDateTime, pub updated_at: NaiveDateTime, + pub verified: bool, } /// Used to create a group in database diff --git a/tasky/src/response/group.rs b/tasky/src/response/group.rs index 33ec408..66966e5 100644 --- a/tasky/src/response/group.rs +++ b/tasky/src/response/group.rs @@ -18,6 +18,7 @@ pub struct GroupResponse { pub tutor: User, pub request_count: i32, pub join_policy: JoinRequestPolicy, + pub verified: bool, } /// The minified group response @@ -28,6 +29,7 @@ pub struct MinifiedGroupResponse { pub member_count: i32, pub tutor: User, pub join_policy: JoinRequestPolicy, + pub verified: bool, } /// The groups response @@ -56,6 +58,7 @@ impl Enrich for MinifiedGroupResponse { member_count: from.members.len() as i32, tutor: tut.into_inner().into(), join_policy: from.join_policy.clone(), + verified: from.verified, }) } } @@ -114,6 +117,7 @@ impl Enrich for GroupResponse { .collect(), tutor: tut.into_inner().into(), join_policy: from.join_policy.clone(), + verified: from.verified, request_count, }) } diff --git a/tasky/src/schema.rs b/tasky/src/schema.rs index 14cd057..7193333 100644 --- a/tasky/src/schema.rs +++ b/tasky/src/schema.rs @@ -85,6 +85,7 @@ diesel::table! { join_policy -> JoinRequestPolicy, created_at -> Timestamp, updated_at -> Timestamp, + verified -> Bool, } } From 34de0b6d352d428c1958dc2f1573431f827a67af Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 19:00:32 +0100 Subject: [PATCH 03/11] feat: Added verification REST endpoints --- tasky/src/routes/group.rs | 48 +++++++++++++++++++++++++++++++++++++++ tasky/src/routes/mod.rs | 2 ++ 2 files changed, 50 insertions(+) diff --git a/tasky/src/routes/group.rs b/tasky/src/routes/group.rs index 8c00c4a..6a20af8 100644 --- a/tasky/src/routes/group.rs +++ b/tasky/src/routes/group.rs @@ -355,3 +355,51 @@ pub async fn delete_group( Ok(HttpResponse::Ok().finish()) } + +/// Endpoint to verify a group +#[post("/groups/{id}/verify")] +pub async fn verify_group( + data: web::Data, + user: web::ReqData, + path: web::Path<(i32,)>, +) -> Result { + let conn = &mut data.db.db.get().unwrap(); + let path_data = path.into_inner(); + + let mut group = GroupRepository::get_by_id(path_data.0, conn).ok_or(ApiError::BadRequest { + message: "No access to group".to_string(), + })?; + + if !StaticSecurity::is_granted(crate::security::StaticSecurityAction::IsAdmin, &user) { + return Err(ApiError::Forbidden { + message: "Only admins are allowed to verify groups".to_string(), + }); + } + group.verified = true; + GroupRepository::update_group(group, conn); + Ok(HttpResponse::Ok().finish()) +} + +/// Endpoint to unverify a group +#[post("/groups/{id}/unverify")] +pub async fn unverify_group( + data: web::Data, + user: web::ReqData, + path: web::Path<(i32,)>, +) -> Result { + let conn = &mut data.db.db.get().unwrap(); + let path_data = path.into_inner(); + + let mut group = GroupRepository::get_by_id(path_data.0, conn).ok_or(ApiError::BadRequest { + message: "No access to group".to_string(), + })?; + + if !StaticSecurity::is_granted(crate::security::StaticSecurityAction::IsAdmin, &user) { + return Err(ApiError::Forbidden { + message: "Only admins are allowed to unverify groups".to_string(), + }); + } + group.verified = false; + GroupRepository::update_group(group, conn); + Ok(HttpResponse::Ok().finish()) +} diff --git a/tasky/src/routes/mod.rs b/tasky/src/routes/mod.rs index 7b43ef1..2d8abe5 100644 --- a/tasky/src/routes/mod.rs +++ b/tasky/src/routes/mod.rs @@ -32,6 +32,8 @@ pub fn init_services(cfg: &mut web::ServiceConfig) { .service(group::remove_user) .service(group::leave_group) .service(group::delete_group) + .service(group::verify_group) + .service(group::unverify_group) .service(group_join_request::create_join_request) .service(group_join_request::get_join_requests) .service(group_join_request::approve_join_request) From 8a0e1136ba07c038195dca79962d60d61da7c8be Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 19:03:46 +0100 Subject: [PATCH 04/11] feat: Added order to rank verifed groups higher than others --- tasky/src/models/group.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index 27c4b3e..104f31f 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -111,6 +111,7 @@ impl GroupRepository { .eq(member_id) .or(dsl::members.contains(vec![Some(member_id)])), ) + .order(dsl::verified.desc()) .paginate(page) .load_and_count_pages::(conn) .expect("Cannot fetch groups for member") @@ -142,6 +143,7 @@ impl GroupRepository { let results = dsl::groups .into_boxed() .filter(apply_search_filter(member_id, requested, search)) + .order(dsl::verified.desc()) .limit(50) .offset((page - 1) * 50) .load::(conn) From 5241664a915199d4ce25becf8ecc7a49c77b085e Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 23:12:27 +0100 Subject: [PATCH 05/11] fix: Fixed fetching with group_by --- tasky/src/models/group.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index 104f31f..961a188 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -111,6 +111,7 @@ impl GroupRepository { .eq(member_id) .or(dsl::members.contains(vec![Some(member_id)])), ) + .group_by((dsl::id, dsl::verified)) .order(dsl::verified.desc()) .paginate(page) .load_and_count_pages::(conn) @@ -141,6 +142,7 @@ impl GroupRepository { .expect("Result cannot be fetched"); let results = dsl::groups + .group_by((dsl::id, dsl::verified)) .into_boxed() .filter(apply_search_filter(member_id, requested, search)) .order(dsl::verified.desc()) From d41978cc268e57cbf8a9727d293732f68ddbb8a6 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 23:24:45 +0100 Subject: [PATCH 06/11] feat: Added group verification in frontend --- web/app/groups/[groupId]/page.tsx | 20 ++++++++++++++++++++ web/app/groups/displayComponent.tsx | 4 ++++ web/components/VerifiedBadge.tsx | 17 +++++++++++++++++ web/public/locales/de/common.json | 2 ++ web/public/locales/de/group.json | 10 +++++++--- web/public/locales/en/common.json | 2 ++ web/public/locales/en/group.json | 10 +++++++--- web/service/ApiService.ts | 8 ++++++++ web/service/types/tasky.ts | 1 + 9 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 web/components/VerifiedBadge.tsx diff --git a/web/app/groups/[groupId]/page.tsx b/web/app/groups/[groupId]/page.tsx index c51dec6..81a55de 100644 --- a/web/app/groups/[groupId]/page.tsx +++ b/web/app/groups/[groupId]/page.tsx @@ -15,6 +15,8 @@ import {isGranted} from "@/service/auth"; import {UserRoles} from "@/service/types/usernator"; import LeaveGroupModal from "@/components/group/LeaveGroupModal"; import DeleteGroupModal from "@/components/group/DeleteGroupModal"; +import VerifiedBadge from "@/components/VerifiedBadge"; +import NavigateBack from "@/components/NavigateBack"; const GroupDetailsPage = ({ params }: { params: { groupId: string } }) => { const id = parseInt(`${params.groupId}`, 10); @@ -27,6 +29,17 @@ const GroupDetailsPage = ({ params }: { params: { groupId: string } }) => { const [deleteModalOpen, setDeleteModalOpen] = useState(false); const { t } = useTranslation("common"); + const changeVerifiedState = async () => { + if (group) { + if (group.verified) { + await api.unverify(group.id); + } else { + await api.verify(group.id); + } + refetch(); + } + } + useEffect(() => { if (group) { addGroup(group); @@ -43,12 +56,16 @@ const GroupDetailsPage = ({ params }: { params: { groupId: string } }) => { return ( + {group?.title ?? "Loading"} {group?.tutor?.username ?? "Loading"} {group?.join_policy && ( )} + {group?.verified && ( + + )} {(isGranted(user, [UserRoles.Admin]) || group?.tutor.id === user?.id) && ( <> @@ -58,6 +75,9 @@ const GroupDetailsPage = ({ params }: { params: { groupId: string } }) => { {isGranted(user, [UserRoles.Student]) && ( )} + {isGranted(user, [UserRoles.Admin]) && ( + + )} {group === null ? ( diff --git a/web/app/groups/displayComponent.tsx b/web/app/groups/displayComponent.tsx index bac9b51..b3167c5 100644 --- a/web/app/groups/displayComponent.tsx +++ b/web/app/groups/displayComponent.tsx @@ -12,6 +12,7 @@ import useCurrentUser from "@/hooks/useCurrentUser"; import { isGranted } from "@/service/auth"; import { useTranslation } from "react-i18next"; import GroupJoinPolicyBadge from "@/components/group/GroupJoinPolicyBadge"; +import VerifiedBadge from "@/components/VerifiedBadge"; interface DisplayComponentProps { groups: MinifiedGroup[]; @@ -34,6 +35,9 @@ const GroupsDisplayComponent = ({ { field: "title", label: t("group:cols.title"), + render: (title, row) => ( +

{title} {row.verified ? : null}

+ ) }, { field: "member_count", diff --git a/web/components/VerifiedBadge.tsx b/web/components/VerifiedBadge.tsx new file mode 100644 index 0000000..67692be --- /dev/null +++ b/web/components/VerifiedBadge.tsx @@ -0,0 +1,17 @@ +import {useTranslation} from "react-i18next"; +import {Badge} from "@mantine/core"; +import {Tooltip} from "@mantine/core"; + + +const VerifiedBadge = () => { + + const {t} = useTranslation("group"); + + return ( + + {t('group:cols.verified')} ✓ + + ); +} + +export default VerifiedBadge; diff --git a/web/public/locales/de/common.json b/web/public/locales/de/common.json index 2bd0e86..8484c8e 100644 --- a/web/public/locales/de/common.json +++ b/web/public/locales/de/common.json @@ -5,6 +5,8 @@ "report-bug": "Fehler melden", "students": "Studierende", "tutors": "Tutoren", + "yes": "Ja", + "no": "Nein", "titles": { "create-tutor": "Tutor erstellen", "spotlight-actions": "Spotlight-Aktionen", diff --git a/web/public/locales/de/group.json b/web/public/locales/de/group.json index 37cd560..2579b30 100644 --- a/web/public/locales/de/group.json +++ b/web/public/locales/de/group.json @@ -11,7 +11,8 @@ "title": "Titel", "members-count": "Anzahl der Mitglieder", "tutor": "Tutor", - "join-policy": "Betrittsrestriktionen" + "join-policy": "Betrittsrestriktionen", + "verified": "Verifiziert" }, "join-policy": { "request": "Anfrage", @@ -23,7 +24,9 @@ "create-group": "Gruppe erstellen", "enlist-user": "Nutzer einschreiben", "enlist": "Einschreiben", - "leave": "Verlassen" + "leave": "Verlassen", + "verify": "Verifizieren", + "unverify": "Entverifizieren" }, "messages": { "join-request-created-title": "Beitrittsanfrage erstellt", @@ -36,6 +39,7 @@ }, "text": { "leave-group": "Bist du sicher, dass du die Gruppe verlassen möchtest?", - "delete-group": "Bist du sicher, dass du die Gruppe löschen möchtest?" + "delete-group": "Bist du sicher, dass du die Gruppe löschen möchtest?", + "verified-tooltip": "Diese Gruppe wurde von dem Administrator verifiziert. Das bedeutet, er hat die bestehenden Inhalte überprüft und diese als sinnvoll und korrekt festgestellt." } } diff --git a/web/public/locales/en/common.json b/web/public/locales/en/common.json index 987623a..e3d8e45 100644 --- a/web/public/locales/en/common.json +++ b/web/public/locales/en/common.json @@ -5,6 +5,8 @@ "report-bug": "Report bug", "students": "Students", "tutors": "Tutors", + "yes": "Yes", + "no": "No", "titles": { "create-tutor": "Create Tutor", "spotlight-actions": "Spotlight actions", diff --git a/web/public/locales/en/group.json b/web/public/locales/en/group.json index aeb3894..ebd107a 100644 --- a/web/public/locales/en/group.json +++ b/web/public/locales/en/group.json @@ -11,7 +11,8 @@ "title": "Title", "members-count": "Members count", "tutor": "Tutor", - "join-policy": "Join policy" + "join-policy": "Join policy", + "verified": "Verified" }, "join-policy": { "request": "Request", @@ -23,7 +24,9 @@ "create-group": "Create group", "enlist-user": "Enlist user", "enlist": "Enlist", - "leave": "Leave" + "leave": "Leave", + "verify": "Verify", + "unverify": "Unverify" }, "messages": { "join-request-created-title": "Join Request created", @@ -36,6 +39,7 @@ }, "text": { "leave-group": "Are you sure you want to leave the group?", - "delete-group": "Are you sure you want to delete the group?" + "delete-group": "Are you sure you want to delete the group?", + "verified-tooltip": "This group has been verified by the administrator. He ensured the contents of the groups are valid and good." } } diff --git a/web/service/ApiService.ts b/web/service/ApiService.ts index 828a11a..e20bf90 100644 --- a/web/service/ApiService.ts +++ b/web/service/ApiService.ts @@ -341,6 +341,14 @@ class ApiService { return await this.get(`/tasky/student_pending_assignments?page=${page}`); } + public async verify(groupId: number): Promise { + await this.post(`/tasky/groups/${groupId}/verify`, {}); + } + + public async unverify(groupId: number): Promise { + await this.post(`/tasky/groups/${groupId}/unverify`, {}); + } + public async createOrUpdateCodeTests( groupId: number, assignmentId: number, diff --git a/web/service/types/tasky.ts b/web/service/types/tasky.ts index e01b014..75d60a7 100644 --- a/web/service/types/tasky.ts +++ b/web/service/types/tasky.ts @@ -27,6 +27,7 @@ export interface Group { tutor: TaskyUser; request_count: number; join_policy: GroupJoinRequestPolicy; + verified: boolean; } export interface TaskyUser { From c909042241903a487c5b92e3b14640c7aebc3ff8 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 23:27:43 +0100 Subject: [PATCH 07/11] fix: Fixed test implementations --- tasky/tests/security/group_test.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tasky/tests/security/group_test.rs b/tasky/tests/security/group_test.rs index 20cbb9d..a9e84d6 100644 --- a/tasky/tests/security/group_test.rs +++ b/tasky/tests/security/group_test.rs @@ -24,6 +24,7 @@ fn test_create_group() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Create, &admin), false); } @@ -41,6 +42,7 @@ fn test_read_group_as_admin() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Read, &admin), true); } @@ -58,6 +60,7 @@ fn test_read_group_as_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Read, &admin), true); } @@ -75,6 +78,7 @@ fn test_read_group_as_wrong_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Read, &admin), false); } @@ -92,6 +96,7 @@ fn test_read_group_as_student() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Read, &admin), true); } @@ -109,6 +114,7 @@ fn test_read_group_as_wrong_student() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Read, &admin), false); } @@ -126,6 +132,7 @@ fn test_update_as_admin() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Update, &user), true); } @@ -143,6 +150,7 @@ fn test_update_as_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Update, &user), true); } @@ -160,6 +168,7 @@ fn test_update_as_wrong_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Update, &user), false); } @@ -177,6 +186,7 @@ fn test_update_as_student() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Update, &user), false); } @@ -194,6 +204,7 @@ fn test_delete_as_admin() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Delete, &user), false); } @@ -211,6 +222,7 @@ fn test_delete_as_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Delete, &user), false); } @@ -228,6 +240,7 @@ fn test_delete_as_wrong_tutor() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Delete, &user), false); } @@ -245,6 +258,7 @@ fn test_delete_as_student() { .unwrap(), updated_at: NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S") .unwrap(), + verified: false, }; assert_eq!(group.is_granted(SecurityAction::Delete, &user), false); } From 2bdb589904077c81a767e3469486f83e1be495b1 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 23:30:02 +0100 Subject: [PATCH 08/11] chore: Updated dashboard release notes --- web/app/dashboard/page.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/web/app/dashboard/page.tsx b/web/app/dashboard/page.tsx index a207df4..ff95a5e 100644 --- a/web/app/dashboard/page.tsx +++ b/web/app/dashboard/page.tsx @@ -32,19 +32,16 @@ const DashboardPage = () => { - Release v0.2.1 + Release v0.2.2 We had some groundbreaking changes within our app for the current release:
- - JavaFX support
+ - Verified groups
+ - Group leaving and deletion
+ - Group join policy feature update
- Notification system
- - Stage3 Spotlight
- - Assignment test editing
- - Completion indicator on assignments
- - Some more backlinks
- - Big performance improvements for web
- - Minor bug fixes + - Convert to tutor account
From cc311c4f2656649d4a1b308e076301cf358d1d39 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Mon, 18 Nov 2024 23:56:10 +0100 Subject: [PATCH 09/11] fix: Fixed tests --- tasky/src/models/group.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index 961a188..ed6d46c 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -105,7 +105,7 @@ impl GroupRepository { page: i64, conn: &mut DB, ) -> PaginatedModel { - dsl::groups + let result = dsl::groups .filter( dsl::tutor .eq(member_id) @@ -114,8 +114,16 @@ impl GroupRepository { .group_by((dsl::id, dsl::verified)) .order(dsl::verified.desc()) .paginate(page) - .load_and_count_pages::(conn) - .expect("Cannot fetch groups for member") + .load_and_count_pages::(conn); + if result.is_err() { + return PaginatedModel { + results: vec![], + total: 0, + page, + }; + } else { + return result.unwrap(); + } } /// Gets all groups a user is member or tutor of @@ -148,12 +156,19 @@ impl GroupRepository { .order(dsl::verified.desc()) .limit(50) .offset((page - 1) * 50) - .load::(conn) - .expect("Result cannot be fetched"); + .load::(conn); + + if results.is_err() { + return PaginatedModel { + total: 0, + results: vec![], + page, + }; + } PaginatedModel { total, - results, + results: results.unwrap(), page, } } From 125c168b2c23d051472d3070a84dabbe5cdc7ec9 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Tue, 19 Nov 2024 00:05:35 +0100 Subject: [PATCH 10/11] chore: Fixed linting errors --- tasky/src/models/group.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index ed6d46c..6e6a333 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -116,13 +116,13 @@ impl GroupRepository { .paginate(page) .load_and_count_pages::(conn); if result.is_err() { - return PaginatedModel { + PaginatedModel { results: vec![], total: 0, page, - }; + } } else { - return result.unwrap(); + result.unwrap() } } From f68cd7cd3a35fe83bb994efde45651d4195a15c0 Mon Sep 17 00:00:00 2001 From: Mathis Burger Date: Tue, 19 Nov 2024 00:09:48 +0100 Subject: [PATCH 11/11] chore: Fixed linting errors --- tasky/src/models/group.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasky/src/models/group.rs b/tasky/src/models/group.rs index 6e6a333..edbd084 100644 --- a/tasky/src/models/group.rs +++ b/tasky/src/models/group.rs @@ -115,14 +115,14 @@ impl GroupRepository { .order(dsl::verified.desc()) .paginate(page) .load_and_count_pages::(conn); - if result.is_err() { + if let Ok(model) = result { + model + } else { PaginatedModel { results: vec![], total: 0, page, } - } else { - result.unwrap() } }