Fix mark-complete 403 for course creators previewing lessons
Creators preview courses without enrolling, so markComplete and SCORM onComplete were hitting the progress endpoint and getting 403. Now guarded by enrollment check — buttons hidden and callbacks skipped for non-enrolled users. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2db5cb74d7
commit
b32fc65236
1 changed files with 4 additions and 3 deletions
|
|
@ -193,6 +193,7 @@ export default function CourseDetailPage() {
|
|||
}
|
||||
|
||||
const markComplete = async (lessonId) => {
|
||||
if (!course.my_enrollment) return
|
||||
try {
|
||||
await api.put(`/courses/${courseId}/lessons/${lessonId}/progress`, { status: 'completed' })
|
||||
setCompletedLessons(prev => { const n = new Set(prev); n.add(lessonId); return n })
|
||||
|
|
@ -386,12 +387,12 @@ export default function CourseDetailPage() {
|
|||
)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
{!completedLessons.has(activeLesson.id) && (
|
||||
{enrolled && !completedLessons.has(activeLesson.id) && (
|
||||
<button className="btn btn-primary btn-sm" onClick={() => markComplete(activeLesson.id)}>
|
||||
Mark Complete ✓
|
||||
</button>
|
||||
)}
|
||||
{completedLessons.has(activeLesson.id) && (
|
||||
{enrolled && completedLessons.has(activeLesson.id) && (
|
||||
<span style={{ color: 'var(--correct-fg)', fontWeight: 600, fontSize: '0.88rem', padding: '6px 0' }}>
|
||||
✓ Completed
|
||||
</span>
|
||||
|
|
@ -555,7 +556,7 @@ export default function CourseDetailPage() {
|
|||
lessonId={activeLesson.id}
|
||||
courseId={courseId}
|
||||
onComplete={() => {
|
||||
if (!completedLessons.has(activeLesson.id)) {
|
||||
if (enrolled && !completedLessons.has(activeLesson.id)) {
|
||||
markComplete(activeLesson.id)
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue