Skip to content

Fixing permission problems with applications #571

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

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

viktorcsimma
Copy link
Contributor

The problem was that old names of policies were used instead of the new ones in ApplicationFormPolicy. Therefore, applications did not appear correctly and unfinished applications were hidden.

@viktorcsimma viktorcsimma added the bug Something isn't working label Jul 16, 2024
@viktorcsimma viktorcsimma self-assigned this Jul 16, 2024
@viktorcsimma viktorcsimma requested a review from a team as a code owner July 16, 2024 10:17
Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Walkthrough

Walkthrough

This update refines the permission checks within the application management system. The revision focuses on ensuring the correct abilities are verified for viewing, editing, and finalising applications. These changes affect both the backend logic and the frontend Blade templates, enhancing the accuracy and security of permission handling.

Changes

File Path Change Summary
app/Http/Controllers/Auth/ApplicationController.php Modified permission check logic in showApplications to use a different method and target class.
resources/views/auth/application/application.blade.php Updated @can directives to check different abilities for viewing and editing applications.
resources/views/auth/application/applications.blade.php Adjusted @can directives to reference new abilities; corrected route for form submission.
resources/views/auth/application/status.blade.php Altered permission checks for viewing and handling application status based on new conditions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ApplicationController
    participant ApplicationModel
    participant BladeTemplate
    
    User->>ApplicationController: View Applications
    ApplicationController->>ApplicationModel: Check permissions for viewUnfinished
    ApplicationModel->>ApplicationController: Permissions verified
    ApplicationController->>BladeTemplate: Render applications view
    
    Note right of BladeTemplate: Application.blade.php
    BladeTemplate->>BladeTemplate: @can('view', $user->application)
    User-->>BladeTemplate: Interacts with the view

    loop Edit Application Status
        User->>ApplicationController: Edit Application Status
        ApplicationController->>ApplicationModel: Check permissions for editStatus
        ApplicationModel->>ApplicationController: Permissions verified
        ApplicationController->>BladeTemplate: Render status form
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
app/Http/Controllers/Auth/ApplicationController.php (1)

166-166: Missing viewUnfinished method in ApplicationFormPolicy

The viewUnfinished permission check in ApplicationController references a method that does not exist in the ApplicationFormPolicy class. Please ensure that the viewUnfinished method is correctly defined and implemented in the ApplicationFormPolicy class.

  • File: app/Http/Controllers/Auth/ApplicationController.php
  • Line: 166
  • Class: ApplicationFormPolicy
  • Missing Method: viewUnfinished
Analysis chain

Confirm correct implementation of the updated permission check.

The updated permission check using @can('viewUnfinished', \App\Models\ApplicationForm::class) appears to be aligned with the PR objectives. However, confirm that this permission is correctly defined and implemented in the backend.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Confirm the correct implementation of the 'viewUnfinished' permission.
ast-grep --lang php --pattern $'class ApplicationFormPolicy {
  $$$
  viewUnfinished($_, $_) {
    $$$
  }
  $$$  
}'

Length of output: 225


Script:

#!/bin/bash
# Description: Confirm the correct implementation of the 'viewUnfinished' permission.
rg -A 5 "class ApplicationFormPolicy" --glob "**/*.php" | rg -A 5 "function viewUnfinished"

Length of output: 93


Script:

#!/bin/bash
# Description: List all methods in policy classes to confirm the existence of the 'viewUnfinished' method.
rg -A 10 "class .*Policy" --glob "**/*.php"

Length of output: 14046

@BertalanD
Copy link
Member

(I don't know anything about PHP...) Is there a static analyzer/type checker that could catch problems like this one before broken code is deployed?

@kdmnk maybe?

@kdmnk
Copy link
Contributor

kdmnk commented Jul 16, 2024

I have this in progress: #553
But I doubt that phpstan is checking laravel specific behavior. We are also improving our test coverage which will help. Otherwise, no, sadly.

Copy link
Contributor

@kdmnk kdmnk left a comment

Choose a reason for hiding this comment

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

LGTM, I'm just wondering what did we merge to get into this state

@viktorcsimma viktorcsimma merged commit 7d0649f into development Jul 16, 2024
6 checks passed
@viktorcsimma viktorcsimma deleted the application-fix-permissions branch July 16, 2024 11:22
@horcsinbalint
Copy link
Member

I'm just wondering what did we merge to get into this state

AFAIK the problematic code was introduced in #532 which was deployed to production by #551 because #542 depended on it (although I advised against deploying it in #542 (comment)).

@kdmnk
Copy link
Contributor

kdmnk commented Jul 18, 2024

I have this in progress: #553 But I doubt that phpstan is checking laravel specific behavior. We are also improving our test coverage which will help. Otherwise, no, sadly.

Update: I found https://github.com/larastan/larastan which allegedly checks Laravel's "beautiful magic" 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants