Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial groups: Change channel prefix for tutorial-groups #7316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ private Channel createTutorialGroupChannel(TutorialGroup tutorialGroup) {
private String determineUniqueTutorialGroupChannelName(TutorialGroup tutorialGroup) {
Function<TutorialGroup, String> determineInitialTutorialGroupChannelName = (TutorialGroup tg) -> {
var cleanedTitle = tg.getTitle().replaceAll("\\s", "-").toLowerCase();
// we use $ as prefix to make sure that the channel name is unique (users not allowed to start channel names with $)
return "$" + cleanedTitle.substring(0, Math.min(cleanedTitle.length(), 19));
return "tutorgroup-" + cleanedTitle.substring(0, Math.min(cleanedTitle.length(), 18));
};

var channelName = determineInitialTutorialGroupChannelName.apply(tutorialGroup);
Expand All @@ -260,14 +259,14 @@ private String determineUniqueTutorialGroupChannelName(TutorialGroup tutorialGro

// try to make it unique by adding a random number to the end of the channel name
// if already max length remove the last 3 characters to get some space to try to make it unique
if (channelName.length() == 20) {
channelName = channelName.substring(0, 17);
if (channelName.length() == 30) {
channelName = channelName.substring(0, 27);
}
while (!channelRepository.findChannelByCourseIdAndName(tutorialGroup.getCourse().getId(), channelName).isEmpty() && channelName.length() <= 20) {
while (!channelRepository.findChannelByCourseIdAndName(tutorialGroup.getCourse().getId(), channelName).isEmpty() && channelName.length() <= 30) {
channelName += ThreadLocalRandom.current().nextInt(0, 10);
}

if (channelName.length() > 20) {
if (channelName.length() > 30) {
// very unlikely to happen
throw new IllegalStateException("Could not create a unique channel name for tutorial group with id " + tutorialGroup.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Channel asserTutorialGroupChannelIsCorrectlyConfigured(TutorialGroup tutorialGro

Function<TutorialGroup, String> expectedTutorialGroupName = (TutorialGroup tg) -> {
var cleanedTitle = tg.getTitle().replaceAll("\\s", "-").toLowerCase();
return "$" + cleanedTitle.substring(0, Math.min(cleanedTitle.length(), 19));
return "tutorgroup-" + cleanedTitle.substring(0, Math.min(cleanedTitle.length(), 18));
};
var tutorialGroupFromDb = tutorialGroupRepository.findByIdWithTeachingAssistantAndRegistrationsElseThrow(tutorialGroup.getId());

Expand Down
Loading