mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-18 11:20:49 +01:00
Fix TwoFAccounts assignment when destination group does not exist
This commit is contained in:
parent
faada93720
commit
194eb54335
@ -108,25 +108,27 @@ public function delete($ids) : int
|
|||||||
*
|
*
|
||||||
* @param array|int $ids accounts ids to assign
|
* @param array|int $ids accounts ids to assign
|
||||||
* @param Group $group The target group
|
* @param Group $group The target group
|
||||||
* @return Group The updated group
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function assign($ids, Group $group = null) : Group
|
public function assign($ids, Group $group = null) : void
|
||||||
{
|
{
|
||||||
if (!$group) {
|
if (!$group) {
|
||||||
$group = $this->destinationGroup();
|
$group = $this->defaultGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($ids)) {
|
if ($group) {
|
||||||
$ids = array($ids);
|
// saveMany() expect an iterable so we pass an array to
|
||||||
|
// find() to always obtain a list of TwoFAccount
|
||||||
|
if (!is_array($ids)) {
|
||||||
|
$ids = array($ids);
|
||||||
|
}
|
||||||
|
$twofaccounts = TwoFAccount::find($ids);
|
||||||
|
|
||||||
|
$group->twofaccounts()->saveMany($twofaccounts);
|
||||||
}
|
}
|
||||||
$twofaccounts = TwoFAccount::find($ids);
|
|
||||||
|
|
||||||
$group->twofaccounts()->saveMany($twofaccounts);
|
|
||||||
$group->loadCount('twofaccounts');
|
|
||||||
|
|
||||||
return $group;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds twofaccounts assigned to the group
|
* Finds twofaccounts assigned to the group
|
||||||
*
|
*
|
||||||
@ -144,9 +146,9 @@ public function getAccounts(Group $group) : Collection
|
|||||||
/**
|
/**
|
||||||
* Determines the destination group
|
* Determines the destination group
|
||||||
*
|
*
|
||||||
* @return Group The group
|
* @return Group|null The group or null if it does not exist
|
||||||
*/
|
*/
|
||||||
private function destinationGroup() : Group
|
private function defaultGroup()
|
||||||
{
|
{
|
||||||
$id = $this->settingService->get('defaultGroup') === '-1' ? (int) $this->settingService->get('activeGroup') : (int) $this->settingService->get('defaultGroup');
|
$id = $this->settingService->get('defaultGroup') === '-1' ? (int) $this->settingService->get('activeGroup') : (int) $this->settingService->get('defaultGroup');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user