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

Modify backpack to allow league admin event control #405

Merged

Conversation

RobertoNittolo
Copy link
Collaborator

@RobertoNittolo RobertoNittolo commented Feb 19, 2022

Description

Closes #374 #421

  • Allow access to backpack for league admins
  • Restrict sidebar based on role
  • Restrict access to all controllers except Event and Session
  • Filter index for league admins
  • Create, edit, show, delete checks to ensure league admin is allowed to perform said action on specific events and sessions

@RobertoNittolo RobertoNittolo added enhancement New feature or request back end labels Feb 19, 2022
@RobertoNittolo RobertoNittolo added this to the Sprint #7 milestone Feb 19, 2022
@RobertoNittolo RobertoNittolo self-assigned this Feb 19, 2022
@codeclimate
Copy link

codeclimate bot commented Feb 19, 2022

Code Climate has analyzed commit 4490ea9 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 96.4% (90% is the threshold).

This pull request will bring the total coverage in the repository to 92.2% (0.5% change).

View more on Code Climate.

Copy link
Contributor

@m-triassi m-triassi left a comment

Choose a reason for hiding this comment

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

couple things i noticed

app/Models/Traits/Accessible.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/SessionCrudController.php Outdated Show resolved Hide resolved
Copy link
Contributor

@m-triassi m-triassi left a comment

Choose a reason for hiding this comment

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

After looking at this more closely, i realized theres a whole settings / access API in the crud panel that we're not leveraging which would make this much simpler.

The way we'd use it is pretty straight forward, in the accessible trait, you'd change the method implementation to look like this:

if (!Auth::user()->isSiteAdmin()) {
    $this->crud->denyAccess(['create', 'show', 'list', 'reorder', 'delete']);
}

Then for the two crud panels that users have access too you just need to filter the lists and deny access on the show / list, much like you're doing now. you can keep as a abort(403), but its probably better to call $this->crud->denyAction('show') / $this->crud->denyAction('list'), etc.. If you dont follow, we can schedule a call to talk about it

app/Http/Controllers/Admin/SessionCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/EventCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/EventCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/EventCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/SessionCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Admin/SessionCrudController.php Outdated Show resolved Hide resolved
Comment on lines 122 to 125
public function isLeagueAdminRole(): bool
{
return $this->hasRole(Role::LEAGUE_ADMIN);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be preferable to have modified the function below this one to allow no $leagueId to be passed and just check if they are a league admin at all

Copy link
Collaborator

@IanjhPhillips IanjhPhillips left a comment

Choose a reason for hiding this comment

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

Wow! very good work.

I'm not sure if this is by deisgn or if im missing something here.
I did the following steps to get to the screenshot:

  • registered a new account (so i can log in / out)
  • logged in as site admin and attached league admin role to user
  • logged out and then back in as my test acc
  • verified that I can see the admin panel (and only saw the event and sessions sidebar)
  • next i tried creating an event, this is where im at in the screenshot

As you can see I have no leagues available to me in the drop down. This is because league id is a pivot value and rn theres no way to modify that through BP i think. (thats fine)

The problem is that despite not technically being an admin of any league, and just having a blank league admin role, I can select sessions that already exist elsewhere (that i did not create) to be part of my event.

I was not able to submit the request as the league field wasnt possible to fill and so the form validation didnt pass. I suspect tho that even if I had some league admin role with a league id pivot value, id still be able to select other leagues' sessions for my event. I also suspect that I'd then be able to submit that request and have those sessions be tied to my event.

Im not quite sure how to fix this or what changes to be made, but I think it is a problem that should be fixed before this is merged.

image

(attaching the league id pivot on user league attachment is possibly out of scope of this task, not sure though)

app/Http/Controllers/Admin/EventCrudController.php Outdated Show resolved Hide resolved
app/Http/Controllers/Traits/Accessible.php Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Mar 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

0.0% 0.0% Coverage
19.6% 19.6% Duplication

Copy link
Contributor

@m-triassi m-triassi left a comment

Choose a reason for hiding this comment

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

Alright i think we've plugged pretty much any holes in this, seems solid now :) good work!

@m-triassi m-triassi merged commit f2f721d into main Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back end enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify backpack to allow league admin event control
3 participants