fix(contributors): add prefix to podcast group to delete contributor

This commit is contained in:
Yassine Doghri 2022-11-03 17:41:50 +00:00
parent e26215a11f
commit 9f785db7ba
2 changed files with 9 additions and 5 deletions

View File

@ -228,7 +228,7 @@ class ContributorController extends BaseController
->delete("podcast#{$this->podcast->id}_contributors");
// remove contributor from podcast group
$this->contributor->removeGroup(get_podcast_group($this->contributor, $this->podcast->id));
$this->contributor->removeGroup(get_podcast_group($this->contributor, $this->podcast->id, false));
return redirect()
->route('contributor-list', [$this->podcast->id])

View File

@ -136,7 +136,7 @@ if (! function_exists('set_instance_group')) {
}
if (! function_exists('get_podcast_group')) {
function get_podcast_group(User $user, int $podcastId): ?string
function get_podcast_group(User $user, int $podcastId, bool $removePrefix = true): ?string
{
$podcastGroups = array_filter($user->getGroups() ?? [], static function ($group) use ($podcastId): bool {
return str_starts_with($group, "podcast#{$podcastId}");
@ -154,8 +154,12 @@ if (! function_exists('get_podcast_group')) {
$user->removeGroup(...$podcastGroups);
}
// strip the `podcast#{id}.` prefix when returning group
return substr((string) $podcastGroup, strlen('podcast#' . $podcastId . '-'));
if ($removePrefix) {
// strip the `podcast#{id}.` prefix when returning group
return substr((string) $podcastGroup, strlen('podcast#' . $podcastId . '-'));
}
return $podcastGroup;
}
}
@ -184,7 +188,7 @@ if (! function_exists('get_podcast_groups')) {
// extract all podcast ids from groups
foreach ($podcastGroups as $podcastGroup) {
// extract podcast id from group and add it to the list of ids
preg_match('~podcast#([0-9]+)-[a-z]+~', $podcastGroup, $matches);
preg_match('~podcast#(\d+)-[a-z]+~', (string) $podcastGroup, $matches);
$userPodcastIds[] = $matches[1];
}