Skip to content

Commit ab108f0

Browse files
Catalogue: Fix showing correct registration button for courses - refs #2805 (#6953)
Co-authored-by: Yannick Warnier <ywarnier@users.noreply.github.com>
1 parent 2ce8b64 commit ab108f0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

assets/vue/components/course/CatalogueCourseCard.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@
140140
/>
141141

142142
<Button
143-
v-else-if="course.subscribe && props.currentUserId"
143+
v-else-if="course.subscribe && props.currentUserId && allowSelfSignup"
144144
:label="$t('Subscribe')"
145145
icon="pi pi-sign-in"
146146
class="w-full"
147147
@click="subscribeToCourse"
148148
/>
149149

150150
<Button
151-
v-else-if="course.visibility === 2 && !course.subscribe && props.currentUserId"
151+
v-else-if="props.currentUserId && !allowSelfSignup"
152152
:label="$t('Subscription not allowed')"
153153
icon="pi pi-ban"
154154
disabled
@@ -343,4 +343,10 @@ const { isLocked, hasRequirements, requirementList, graphImage, fetchStatus } =
343343
onMounted(() => {
344344
fetchStatus()
345345
})
346+
347+
const allowSelfSignup = computed(() => {
348+
if (props.course?.allow_self_signup !== undefined) return Boolean(props.course.allow_self_signup)
349+
if (props.course?.allowSelfSignup !== undefined) return Boolean(props.course.allowSelfSignup)
350+
return props.course?.visibility === 0
351+
})
346352
</script>

src/CoreBundle/Controller/CatalogueController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ public function autoSubscribeCourse(int $courseId, SettingsManager $settings): J
534534
return $this->json(['error' => 'Course or user not found'], 400);
535535
}
536536

537+
$isPrivileged = $this->isGranted('ROLE_ADMIN') || $this->isGranted('ROLE_SESSION_ADMIN');
538+
if (!$course->getAllowSelfSignup() && !$isPrivileged) {
539+
return $this->json(['error' => 'Self sign up not allowed for this course'], 403);
540+
}
541+
542+
537543
$useAutoSession = 'true' === $settings->getSetting('catalog.course_subscription_in_user_s_session', true);
538544

539545
if ($useAutoSession) {

src/CoreBundle/Entity/Course.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
377377
#[Groups(['course:read'])]
378378
public bool $subscribed = false;
379379

380+
#[SerializedName('allowSelfSignup')]
381+
#[Groups(['course:read','session:read'])]
382+
public function getAllowSelfSignup(): bool
383+
{
384+
return $this->visibility !== self::REGISTERED;
385+
}
386+
380387
public function __construct()
381388
{
382389
$this->visibility = self::OPEN_PLATFORM;

0 commit comments

Comments
 (0)