mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-27 20:21:59 +02:00
fix(contributors): add prefix to podcast group to delete contributor
This commit is contained in:
parent
e26215a11f
commit
9f785db7ba
@ -228,7 +228,7 @@ class ContributorController extends BaseController
|
|||||||
->delete("podcast#{$this->podcast->id}_contributors");
|
->delete("podcast#{$this->podcast->id}_contributors");
|
||||||
|
|
||||||
// remove contributor from podcast group
|
// 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()
|
return redirect()
|
||||||
->route('contributor-list', [$this->podcast->id])
|
->route('contributor-list', [$this->podcast->id])
|
||||||
|
@ -136,7 +136,7 @@ if (! function_exists('set_instance_group')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! function_exists('get_podcast_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 {
|
$podcastGroups = array_filter($user->getGroups() ?? [], static function ($group) use ($podcastId): bool {
|
||||||
return str_starts_with($group, "podcast#{$podcastId}");
|
return str_starts_with($group, "podcast#{$podcastId}");
|
||||||
@ -154,8 +154,12 @@ if (! function_exists('get_podcast_group')) {
|
|||||||
$user->removeGroup(...$podcastGroups);
|
$user->removeGroup(...$podcastGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip the `podcast#{id}.` prefix when returning group
|
if ($removePrefix) {
|
||||||
return substr((string) $podcastGroup, strlen('podcast#' . $podcastId . '-'));
|
// 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
|
// extract all podcast ids from groups
|
||||||
foreach ($podcastGroups as $podcastGroup) {
|
foreach ($podcastGroups as $podcastGroup) {
|
||||||
// extract podcast id from group and add it to the list of ids
|
// 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];
|
$userPodcastIds[] = $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user