Commit 9f785db7 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

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

parent e26215a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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])
+8 −4
Original line number Diff line number Diff line
@@ -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,9 +154,13 @@ if (! function_exists('get_podcast_group')) {
            $user->removeGroup(...$podcastGroups);
        }

        if ($removePrefix) {
            // strip the `podcast#{id}.` prefix when returning group
            return substr((string) $podcastGroup, strlen('podcast#' . $podcastId . '-'));
        }

        return $podcastGroup;
    }
}

if (! function_exists('set_podcast_group')) {
@@ -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];
        }