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

Feat/brain access rights #705

Merged
merged 4 commits into from
Jul 19, 2023
Merged

Feat/brain access rights #705

merged 4 commits into from
Jul 19, 2023

Conversation

mamadoudicko
Copy link
Contributor

@mamadoudicko mamadoudicko commented Jul 19, 2023

Description

  • Prevent EDITOR to affect OWNER right (creation and update)
  • Update RBAC logic: supports multiple rights
  • Add rights enum
Screenshot 2023-07-19 at 12 47 14

@mamadoudicko mamadoudicko temporarily deployed to preview July 19, 2023 10:48 — with GitHub Actions Inactive
@mamadoudicko mamadoudicko temporarily deployed to preview July 19, 2023 10:48 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Jul 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2023 10:54am
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2023 10:54am

@github-actions
Copy link
Contributor

github-actions bot commented Jul 19, 2023

LOGAF Level 3 - /home/runner/work/quivr/quivr/backend/core/routes/authorizations/brain_authorization.py

The code is generally good, but there are areas for potential improvement.

  1. The validate_brain_authorization function checks if required_roles is None and raises an exception if it is. However, the default value for required_roles is RoleEnum.Owner, so it will never be None. Consider removing this check.

  2. The has_brain_authorization function converts required_roles to a list if it's a string. This conversion is also done in validate_brain_authorization. Consider removing the conversion from has_brain_authorization to avoid redundancy.

  3. The validate_brain_authorization function retrieves a Brain object and then calls get_brain_for_user on it. This could potentially lead to a database query. Consider passing the Brain object as a parameter to the function to avoid unnecessary database queries.

LOGAF Level 3 - /home/runner/work/quivr/quivr/backend/core/routes/subscription_routes.py

The code is generally good, but there are areas for potential improvement.

  1. The invite_users_to_brain function sends an invitation email to each user in a loop. If there are many users, this could potentially lead to a large number of emails being sent at once. Consider using a queue or a batch process to handle this.

  2. The get_brain_users function retrieves all users for a brain and then fetches the email for each user in a loop. This could potentially lead to a large number of database queries. Consider fetching all emails in a single query.

  3. The remove_user_subscription function checks if the user has permission for the brain and if the user is an owner. These checks are also done in other functions. Consider creating a helper function to avoid redundancy.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/BrainActions.tsx

The code is excellent and needs no changes.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/ShareBrain.tsx

The code is excellent and needs no changes.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/tests/ShareBrain.test.tsx

The code is excellent and needs no changes.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/components/BrainUsers/hooks/useBrainUsers.ts

The code is excellent and needs no changes.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/components/index.ts

The code is excellent and needs no changes.

LOGAF Level 5 - /home/runner/work/quivr/quivr/frontend/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/components/ShareBrain/hooks/useShareBrain.ts

The code is excellent and needs no changes.

/home/runner/work/quivr/quivr/frontend/lib/components/ui/Select.tsx - LOGAF Level 3

This code is generally good, but there are a few areas for potential improvement:

  1. Accessibility: The aria-haspopup attribute is used incorrectly. It should be set to true when the listbox is visible and false when it's not. Currently, it's always set to listbox, which is not a valid value for this attribute.

  2. Code Duplication: The label rendering code is duplicated in both the readOnly and non-readOnly branches. This could be extracted into a separate function to reduce duplication.

  3. Hardcoded IDs: The id attribute for the label and listbox option are hardcoded. This could lead to duplicate IDs if multiple instances of this component are used on the same page, which is not valid HTML and could cause issues with accessibility and functionality.

Here's an example of how you might address these issues:

const renderLabel = (label: string | undefined) => {
  return label !== undefined && (
    <label
      className="block text-sm font-medium leading-6 text-gray-900 mb-2"
    >
      {label}
    </label>
  );
};

// ...

return (
  <div>
    {renderLabel(label)}
    <div className="relative">
      <Popover
        Trigger={
          <button
            type="button"
            className="relative w-full cursor-default rounded-md bg-white py-1.5 pl-3 pr-10 text-left text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 sm:text-sm sm:leading-6"
            aria-haspopup={isOpen ? "true" : "false"}
          >
            {/* ... */}
          </button>
        }
        // ...
      >
        <ul role="listbox">
          {options.map((option, index) => (
            <li
              className="text-gray-900 relative cursor-pointer select-none py-2"
              id={`listbox-option-${index}`}
              key={option.value}
              onClick={() => onChange(option.value)}
            >
              {/* ... */}
            </li>
          ))}
        </ul>
      </Popover>
    </div>
  </div>
);

In this example, isOpen would be a state variable that tracks whether the listbox is currently visible.


👍🔧📚


Powered by Code Review GPT

Copy link
Collaborator

@StanGirard StanGirard left a comment

Choose a reason for hiding this comment

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

Love it ! Congratts

@@ -7,16 +8,27 @@
from models.users import User


def has_brain_authorization(required_role: Optional[str] = "Owner"):
class RoleEnum(str, Enum):
Copy link
Contributor

Choose a reason for hiding this comment

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

Me gustaaa !

@mamadoudicko mamadoudicko merged commit 87458d8 into main Jul 19, 2023
5 of 6 checks passed
StanGirard pushed a commit that referenced this pull request Sep 12, 2023
* refactor(BrainUsers)

* feat: give brain share access to EDITORs

* feat(RBAC): add role enum and supports multiple roles check

* feat: make owner right read only for other permissions
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.

None yet

3 participants