Skip to content

Delete groups with all memberships#453

Open
buyolitsez wants to merge 3 commits into
BeWelcome:developfrom
buyolitsez:fix/80-remove-all-group-memberships
Open

Delete groups with all memberships#453
buyolitsez wants to merge 3 commits into
BeWelcome:developfrom
buyolitsez:fix/80-remove-all-group-memberships

Conversation

@buyolitsez

Copy link
Copy Markdown
Contributor

Clean up orphaned memberships and report deletion failures.

Fixes #80

Clean up orphaned memberships and report deletion failures.

Fixes BeWelcome#80
@thisismeonmounteverest

Copy link
Copy Markdown
Contributor

Instead of fixing this in the legacy code it would be better to add that to the 'new' group controller and model in src/Controller and src/Model.

Comment thread tests/Legacy/GroupDeleteDouble.php Outdated
)]
public function deleteGroup(Group $group, Logger $logger): RedirectResponse
{
/** @var Member|null $member */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member will never be null here as the route is behind the firewall.

{
/** @var Member|null $member */
$member = $this->getUser();
$isGroupsAdmin = $member instanceof Member

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First part of conditional is always true.

&& $this->isGranted(Member::ROLE_ADMIN_GROUP)
&& 10 === $member->getLevelForRight(Member::ROLE_ADMIN_GROUP);
if (!$member instanceof Member || (!$group->isAdmin($member) && !$isGroupsAdmin)) {
throw $this->createAccessDeniedException('No group admin');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is shown to the user but if it is it should be translated.

$inactiveMember = $this->getMember($entityManager, 'member-banned');
$groupId = random_int(1_500_000_000, 2_000_000_000);

try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand this defensive programming style in a test I would not expect that any exception would happen if I execute the method under test.

What's the verdict of the test if the createGroupFixture call fails?

The asserts should always be executed. So if the try block is necessary move the asserts into the finally section.

return $member;
}

private function createGroupFixture(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we still using dama/doctrine-test-bundle? So adding and removing would be part of the test setup and reverted without the need of a finally block.

);
}

private function removeGroupFixture(Connection $connection, int $groupId): void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let dama/doctrine-test-bundle handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Groups are deleted but membership isn't

2 participants