Keep draft practices visible to admin staff and allow multiple Learn English practices per parent.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
edcdaa5bfb
commit
3304d8818f
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELETE FROM lms_practice_parents a
|
||||||
|
USING lms_practice_parents b
|
||||||
|
WHERE a.id > b.id
|
||||||
|
AND a.parent_kind = b.parent_kind
|
||||||
|
AND a.parent_id = b.parent_id;
|
||||||
|
|
||||||
|
ALTER TABLE lms_practice_parents
|
||||||
|
ADD CONSTRAINT lms_practice_parents_parent_kind_parent_id_key UNIQUE (parent_kind, parent_id);
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Learn English: allow multiple practices per course, module, or lesson
|
||||||
|
-- (matches exam-prep 000094). Duplicate links on the same practice remain unique.
|
||||||
|
ALTER TABLE lms_practice_parents
|
||||||
|
DROP CONSTRAINT IF EXISTS lms_practice_parents_parent_kind_parent_id_key;
|
||||||
|
|
@ -88,7 +88,10 @@ SELECT
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM exam_prep.lesson_practices p
|
FROM exam_prep.lesson_practices p
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE p.publish_status = 'PUBLISHED'
|
WHERE (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
AND (
|
AND (
|
||||||
(
|
(
|
||||||
pp.parent_kind = 'CATALOG_COURSE'
|
pp.parent_kind = 'CATALOG_COURSE'
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,10 @@ SELECT
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE pp.parent_kind = 'LESSON'
|
WHERE pp.parent_kind = 'LESSON'
|
||||||
AND pp.parent_id = l.id
|
AND pp.parent_id = l.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice,
|
) AS has_practice,
|
||||||
l.created_at,
|
l.created_at,
|
||||||
l.updated_at
|
l.updated_at
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,10 @@ WITH module_counts AS (
|
||||||
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
||||||
AND pp.parent_id = l.id
|
AND pp.parent_id = l.id
|
||||||
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
GROUP BY m.id
|
GROUP BY m.id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,10 @@ WITH unit_counts AS (
|
||||||
SELECT COUNT(DISTINCT p.id)::BIGINT
|
SELECT COUNT(DISTINCT p.id)::BIGINT
|
||||||
FROM exam_prep.lesson_practices p
|
FROM exam_prep.lesson_practices p
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE p.publish_status = 'PUBLISHED'
|
WHERE (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
AND (
|
AND (
|
||||||
(
|
(
|
||||||
pp.parent_kind = 'UNIT'
|
pp.parent_kind = 'UNIT'
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,20 @@ SELECT
|
||||||
WHERE
|
WHERE
|
||||||
lpp.parent_kind = 'COURSE'
|
lpp.parent_kind = 'COURSE'
|
||||||
AND lpp.parent_id = c.id
|
AND lpp.parent_id = c.id
|
||||||
AND p.publish_status = 'PUBLISHED') AS practice_count,
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)) AS practice_count,
|
||||||
EXISTS (
|
EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM lms_practice_parents lpp
|
FROM lms_practice_parents lpp
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'COURSE'
|
WHERE lpp.parent_kind = 'COURSE'
|
||||||
AND lpp.parent_id = c.id
|
AND lpp.parent_id = c.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
courses c
|
courses c
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,10 @@ SELECT
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'LESSON'
|
WHERE lpp.parent_kind = 'LESSON'
|
||||||
AND lpp.parent_id = l.id
|
AND lpp.parent_id = l.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
lessons l
|
lessons l
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,10 @@ SELECT
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'MODULE'
|
WHERE lpp.parent_kind = 'MODULE'
|
||||||
AND lpp.parent_id = m.id
|
AND lpp.parent_id = m.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
sqlc.arg('published_only')::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
modules m
|
modules m
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,10 @@ SELECT
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM exam_prep.lesson_practices p
|
FROM exam_prep.lesson_practices p
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE p.publish_status = 'PUBLISHED'
|
WHERE (
|
||||||
|
$3::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
AND (
|
AND (
|
||||||
(
|
(
|
||||||
pp.parent_kind = 'CATALOG_COURSE'
|
pp.parent_kind = 'CATALOG_COURSE'
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,10 @@ SELECT
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE pp.parent_kind = 'LESSON'
|
WHERE pp.parent_kind = 'LESSON'
|
||||||
AND pp.parent_id = l.id
|
AND pp.parent_id = l.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice,
|
) AS has_practice,
|
||||||
l.created_at,
|
l.created_at,
|
||||||
l.updated_at
|
l.updated_at
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,10 @@ WITH module_counts AS (
|
||||||
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
||||||
AND pp.parent_id = l.id
|
AND pp.parent_id = l.id
|
||||||
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
GROUP BY m.id
|
GROUP BY m.id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,10 @@ WITH unit_counts AS (
|
||||||
SELECT COUNT(DISTINCT p.id)::BIGINT
|
SELECT COUNT(DISTINCT p.id)::BIGINT
|
||||||
FROM exam_prep.lesson_practices p
|
FROM exam_prep.lesson_practices p
|
||||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||||
WHERE p.publish_status = 'PUBLISHED'
|
WHERE (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
AND (
|
AND (
|
||||||
(
|
(
|
||||||
pp.parent_kind = 'UNIT'
|
pp.parent_kind = 'UNIT'
|
||||||
|
|
|
||||||
|
|
@ -197,14 +197,20 @@ SELECT
|
||||||
WHERE
|
WHERE
|
||||||
lpp.parent_kind = 'COURSE'
|
lpp.parent_kind = 'COURSE'
|
||||||
AND lpp.parent_id = c.id
|
AND lpp.parent_id = c.id
|
||||||
AND p.publish_status = 'PUBLISHED') AS practice_count,
|
AND (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)) AS practice_count,
|
||||||
EXISTS (
|
EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
FROM lms_practice_parents lpp
|
FROM lms_practice_parents lpp
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'COURSE'
|
WHERE lpp.parent_kind = 'COURSE'
|
||||||
AND lpp.parent_id = c.id
|
AND lpp.parent_id = c.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
courses c
|
courses c
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,10 @@ SELECT
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'LESSON'
|
WHERE lpp.parent_kind = 'LESSON'
|
||||||
AND lpp.parent_id = l.id
|
AND lpp.parent_id = l.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
$4::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
lessons l
|
lessons l
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,10 @@ SELECT
|
||||||
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
INNER JOIN lms_practices p ON p.id = lpp.practice_id
|
||||||
WHERE lpp.parent_kind = 'MODULE'
|
WHERE lpp.parent_kind = 'MODULE'
|
||||||
AND lpp.parent_id = m.id
|
AND lpp.parent_id = m.id
|
||||||
AND p.publish_status = 'PUBLISHED'
|
AND (
|
||||||
|
$5::boolean = FALSE
|
||||||
|
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||||
|
)
|
||||||
) AS has_practice
|
) AS has_practice
|
||||||
FROM
|
FROM
|
||||||
modules m
|
modules m
|
||||||
|
|
|
||||||
|
|
@ -429,9 +429,6 @@ func (s *Service) CreateExamPrepPracticeFromInput(ctx context.Context, input dom
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) listExamPrepPractices(ctx context.Context, parent domain.ExamPrepPracticeParent, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
func (s *Service) listExamPrepPractices(ctx context.Context, parent domain.ExamPrepPracticeParent, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||||
if limit <= 0 {
|
|
||||||
limit = 20
|
|
||||||
}
|
|
||||||
if limit > 200 {
|
if limit > 200 {
|
||||||
limit = 200
|
limit = 200
|
||||||
}
|
}
|
||||||
|
|
@ -505,9 +502,6 @@ func (s *Service) ListExamPrepPracticesByUnit(ctx context.Context, unitID int64,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) ListAllExamPrepPractices(ctx context.Context, publishedOnly, unlinkedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
func (s *Service) ListAllExamPrepPractices(ctx context.Context, publishedOnly, unlinkedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||||
if limit <= 0 {
|
|
||||||
limit = 20
|
|
||||||
}
|
|
||||||
if limit > 200 {
|
if limit > 200 {
|
||||||
limit = 200
|
limit = 200
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package practices
|
||||||
import (
|
import (
|
||||||
"Yimaru-Backend/internal/domain"
|
"Yimaru-Backend/internal/domain"
|
||||||
"Yimaru-Backend/internal/ports"
|
"Yimaru-Backend/internal/ports"
|
||||||
"Yimaru-Backend/internal/repository"
|
|
||||||
"Yimaru-Backend/internal/services/courses"
|
"Yimaru-Backend/internal/services/courses"
|
||||||
"Yimaru-Backend/internal/services/lessons"
|
"Yimaru-Backend/internal/services/lessons"
|
||||||
"Yimaru-Backend/internal/services/modules"
|
"Yimaru-Backend/internal/services/modules"
|
||||||
|
|
@ -111,25 +110,6 @@ func (s *Service) validateParentList(ctx context.Context, parents []domain.Pract
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) ensureParentsAvailable(ctx context.Context, parents []domain.PracticeParent, excludePracticeID int64) error {
|
|
||||||
for _, parent := range parents {
|
|
||||||
var count int64
|
|
||||||
var err error
|
|
||||||
if excludePracticeID > 0 {
|
|
||||||
count, err = s.practices.CountLmsPracticesByParentExcludingPractice(ctx, parent.Kind, parent.ID, excludePracticeID)
|
|
||||||
} else {
|
|
||||||
count, err = s.practices.CountLmsPracticesByParent(ctx, parent.Kind, parent.ID)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if count >= 1 {
|
|
||||||
return ErrPracticeParentLimitExceeded
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Create(ctx context.Context, in domain.CreatePracticeInput) (domain.Practice, error) {
|
func (s *Service) Create(ctx context.Context, in domain.CreatePracticeInput) (domain.Practice, error) {
|
||||||
if err := s.validateQuestionSet(ctx, in.QuestionSetID); err != nil {
|
if err := s.validateQuestionSet(ctx, in.QuestionSetID); err != nil {
|
||||||
return domain.Practice{}, err
|
return domain.Practice{}, err
|
||||||
|
|
@ -144,15 +124,8 @@ func (s *Service) Create(ctx context.Context, in domain.CreatePracticeInput) (do
|
||||||
if err := s.validateParentList(ctx, parents); err != nil {
|
if err := s.validateParentList(ctx, parents); err != nil {
|
||||||
return domain.Practice{}, err
|
return domain.Practice{}, err
|
||||||
}
|
}
|
||||||
if err := s.ensureParentsAvailable(ctx, parents, 0); err != nil {
|
|
||||||
return domain.Practice{}, err
|
|
||||||
}
|
}
|
||||||
}
|
return s.practices.CreateLmsPractice(ctx, in, parents)
|
||||||
p, err := s.practices.CreateLmsPractice(ctx, in, parents)
|
|
||||||
if err != nil && repository.IsUniqueViolation(err) {
|
|
||||||
return domain.Practice{}, ErrPracticeParentLimitExceeded
|
|
||||||
}
|
|
||||||
return p, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) TryGetByQuestionSetID(ctx context.Context, questionSetID int64) (domain.Practice, bool, error) {
|
func (s *Service) TryGetByQuestionSetID(ctx context.Context, questionSetID int64) (domain.Practice, bool, error) {
|
||||||
|
|
@ -255,14 +228,8 @@ func (s *Service) UpdateParents(ctx context.Context, id int64, in domain.UpdateP
|
||||||
if err := s.validateParentList(ctx, parents); err != nil {
|
if err := s.validateParentList(ctx, parents); err != nil {
|
||||||
return domain.Practice{}, err
|
return domain.Practice{}, err
|
||||||
}
|
}
|
||||||
if err := s.ensureParentsAvailable(ctx, parents, id); err != nil {
|
|
||||||
return domain.Practice{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := s.practices.ReplaceLmsPracticeParents(ctx, id, parents); err != nil {
|
if err := s.practices.ReplaceLmsPracticeParents(ctx, id, parents); err != nil {
|
||||||
if repository.IsUniqueViolation(err) {
|
|
||||||
return domain.Practice{}, ErrPracticeParentLimitExceeded
|
|
||||||
}
|
|
||||||
return domain.Practice{}, err
|
return domain.Practice{}, err
|
||||||
}
|
}
|
||||||
return s.practices.GetLmsPracticeByID(ctx, id)
|
return s.practices.GetLmsPracticeByID(ctx, id)
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func (h *Handler) ListAllExamPrepPractices(c *fiber.Ctx) error {
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
unlinkedOnly := false
|
unlinkedOnly := false
|
||||||
if h.canManageExamPrepPractices(c) {
|
if h.canManageExamPrepPractices(c) {
|
||||||
unlinkedOnly, _ = strconv.ParseBool(c.Query("unlinked_only", "false"))
|
unlinkedOnly, _ = strconv.ParseBool(c.Query("unlinked_only", "false"))
|
||||||
|
|
@ -146,7 +146,7 @@ func (h *Handler) ListExamPrepPracticesByLesson(c *fiber.Ctx) error {
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByLesson(c.Context(), lessonID, publishedOnly, limit, offset)
|
items, total, err := h.examPrepSvc.ListExamPrepPracticesByLesson(c.Context(), lessonID, publishedOnly, limit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
||||||
|
|
@ -494,7 +494,7 @@ func (h *Handler) ListExamPrepPracticesByCatalogCourse(c *fiber.Ctx) error {
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByCatalogCourse(c.Context(), catalogCourseID, publishedOnly, limit, offset)
|
items, total, err := h.examPrepSvc.ListExamPrepPracticesByCatalogCourse(c.Context(), catalogCourseID, publishedOnly, limit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
||||||
|
|
@ -555,7 +555,7 @@ func (h *Handler) ListExamPrepPracticesByUnit(c *fiber.Ctx) error {
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByUnit(c.Context(), unitID, publishedOnly, limit, offset)
|
items, total, err := h.examPrepSvc.ListExamPrepPracticesByUnit(c.Context(), unitID, publishedOnly, limit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
if resp := h.listExamPrepPracticesResponse(c, nil, 0, int(limit), int(offset), err); resp != nil {
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,7 @@ func (h *Handler) CreatePractice(c *fiber.Ctx) error {
|
||||||
func (h *Handler) ListPractices(c *fiber.Ctx) error {
|
func (h *Handler) ListPractices(c *fiber.Ctx) error {
|
||||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||||
role, _ := c.Locals("role").(domain.Role)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
publishedOnly := role.IsCustomerLearnerRole() || !h.canManageLMSPractices(c)
|
|
||||||
unlinkedOnly := false
|
unlinkedOnly := false
|
||||||
if h.canManageLMSPractices(c) {
|
if h.canManageLMSPractices(c) {
|
||||||
unlinkedOnly, _ = strconv.ParseBool(c.Query("unlinked_only", "false"))
|
unlinkedOnly, _ = strconv.ParseBool(c.Query("unlinked_only", "false"))
|
||||||
|
|
@ -117,8 +116,7 @@ func (h *Handler) ListPracticesByCourse(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||||
role, _ := c.Locals("role").(domain.Role)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
publishedOnly := role.IsCustomerLearnerRole() || !h.canManageLMSPractices(c)
|
|
||||||
items, total, err := h.practiceSvc.ListByCourse(c.Context(), courseID, publishedOnly, int32(limit), int32(offset))
|
items, total, err := h.practiceSvc.ListByCourse(c.Context(), courseID, publishedOnly, int32(limit), int32(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, courses.ErrCourseNotFound) {
|
if errors.Is(err, courses.ErrCourseNotFound) {
|
||||||
|
|
@ -153,8 +151,7 @@ func (h *Handler) ListPracticesByModule(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||||
role, _ := c.Locals("role").(domain.Role)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
publishedOnly := role.IsCustomerLearnerRole() || !h.canManageLMSPractices(c)
|
|
||||||
items, total, err := h.practiceSvc.ListByModule(c.Context(), moduleID, publishedOnly, int32(limit), int32(offset))
|
items, total, err := h.practiceSvc.ListByModule(c.Context(), moduleID, publishedOnly, int32(limit), int32(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, modules.ErrModuleNotFound) {
|
if errors.Is(err, modules.ErrModuleNotFound) {
|
||||||
|
|
@ -189,8 +186,7 @@ func (h *Handler) ListPracticesByLesson(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||||
role, _ := c.Locals("role").(domain.Role)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
publishedOnly := role.IsCustomerLearnerRole() || !h.canManageLMSPractices(c)
|
|
||||||
items, total, err := h.practiceSvc.ListByLesson(c.Context(), lessonID, publishedOnly, int32(limit), int32(offset))
|
items, total, err := h.practiceSvc.ListByLesson(c.Context(), lessonID, publishedOnly, int32(limit), int32(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, lessons.ErrLessonNotFound) {
|
if errors.Is(err, lessons.ErrLessonNotFound) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,14 @@ func (h *Handler) canManageLMSPractices(c *fiber.Ctx) bool {
|
||||||
return h.rbacSvc.HasPermission(rn, "practices.create") || h.rbacSvc.HasPermission(rn, "practices.update")
|
return h.rbacSvc.HasPermission(rn, "practices.create") || h.rbacSvc.HasPermission(rn, "practices.update")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hideUnpublishedPractices is true only for customer learner roles.
|
||||||
|
// Admin-panel staff (including custom RBAC roles with list permission) must see DRAFT shells
|
||||||
|
// on parent practice pages; gating create/update is handled separately by RequirePermission.
|
||||||
|
func (h *Handler) hideUnpublishedPractices(c *fiber.Ctx) bool {
|
||||||
|
role, _ := c.Locals("role").(domain.Role)
|
||||||
|
return role.IsCustomerLearnerRole()
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) canManageLessons(c *fiber.Ctx) bool {
|
func (h *Handler) canManageLessons(c *fiber.Ctx) bool {
|
||||||
rn := string(c.Locals("role").(domain.Role))
|
rn := string(c.Locals("role").(domain.Role))
|
||||||
return h.rbacSvc.HasPermission(rn, "lessons.create") || h.rbacSvc.HasPermission(rn, "lessons.update")
|
return h.rbacSvc.HasPermission(rn, "lessons.create") || h.rbacSvc.HasPermission(rn, "lessons.update")
|
||||||
|
|
|
||||||
|
|
@ -347,8 +347,7 @@ func (h *Handler) ListPracticesByQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||||
|
|
||||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||||
role, _ := c.Locals("role").(domain.Role)
|
publishedOnly := h.hideUnpublishedPractices(c)
|
||||||
publishedOnly := role.IsCustomerLearnerRole() || !h.canManageLMSPractices(c)
|
|
||||||
|
|
||||||
summary, err := h.questionsSvc.ListPracticesByQuestionTypeDefinition(c.Context(), id, publishedOnly, int32(limit), int32(offset))
|
summary, err := h.questionsSvc.ListPracticesByQuestionTypeDefinition(c.Context(), id, publishedOnly, int32(limit), int32(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user