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

Refactor ownersip / authorization #9

Open
itsrachelfish opened this issue Feb 8, 2016 · 1 comment
Open

Refactor ownersip / authorization #9

itsrachelfish opened this issue Feb 8, 2016 · 1 comment

Comments

@itsrachelfish
Copy link
Member

There's some boilerplate I've noticed in controllers that should be refactored. Many controllers need to determine if the current user is the creator of a model object or has permission to view / edit it. This logic could probably be handled by a custom middleware with a couple parameters.

// Did the current user create this application?
if($application->user->id != Auth::user()->id)
{
    $request->session()->flash('error', 'Only the person who created an application may change it.');
    return redirect('/login');
}
@itsrachelfish
Copy link
Member Author

Another example which appears in the ApplicationController and AnswerController:

if($application->status != 'new')
{
    $request->session()->flash('error', 'Your application has been submitted, you may no longer make changes.');
    return redirect('/applications/' . $application->id . '/review');
}

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

No branches or pull requests

1 participant