Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manage): sync dev role attach/detach with legacy permissions value #2878

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

wescopeland
Copy link
Member

@wescopeland wescopeland commented Nov 23, 2024

Resolves an issue where attaching/detaching developer roles from the management app does not synchronize that user's legacy Permissions value.

In other words, you can attach a Junior Developer role, but their permissions value won't be automatically updated to 2.


After deploy, run:

UPDATE `auth_roles` SET `name` = 'developer-retired' WHERE `name` = 'developer-veteran';

@wescopeland wescopeland requested a review from a team November 23, 2024 17:39
Copy link
Member

@Jamiras Jamiras left a comment

Choose a reason for hiding this comment

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

I have many reservations about this implementation. If a Moderator applies for Jr. Dev, they'll automatically have their Permissions lowered. Similarly, if they give up being a developer, they'll get reset to Registered.

It probably makes sense to keep these changes, but only apply them for users under Moderator permissions level.

app/Filament/Resources/UserResource/Pages/Roles.php Outdated Show resolved Hide resolved
@wescopeland wescopeland added the deployment/sql Includes SQL that needs to be run before/after deployment label Nov 24, 2024
@wescopeland
Copy link
Member Author

It probably makes sense to keep these changes, but only apply them for users under Moderator permissions level.

I believe this should now be done in latest. The role attach/detach is still in place for all users as before, but permissions are not reassigned unless $currentPermissions < Permissions::Moderator.

Role::DEVELOPER_RETIRED,
])) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Having this as a secondary gate duplicates the lower logic and creates an opportunity for them to become desync'd. Suggest adding an else return to the logic below:

else
{
    // nothing to synchronize for non-developer roles. we're done
    return;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in latest.

Copy link
Member

Choose a reason for hiding this comment

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

I think you missed my point. You're still checking the conditions twice.

Instead of:

if (in_array(A, B)) {
    if (A) {
    } elseif (B) {
    }
    do_stuff();
}

just do:

if (A) {
} elseif (B) {
} else {
    return;
}
do_stuff();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment/sql Includes SQL that needs to be run before/after deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants