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: activate public brain subscription #1241

Merged
merged 7 commits into from
Sep 22, 2023
Merged

feat: activate public brain subscription #1241

merged 7 commits into from
Sep 22, 2023

Conversation

mamadoudicko
Copy link
Contributor

@mamadoudicko mamadoudicko commented Sep 21, 2023

  • Add last_update logic to brain entity
  • Add /Post subscribe endpoint to subscribe to a public brain
  • Add public brain details modal
Screen.Recording.2023-09-21.at.18.04.53.mp4

#1210

@mamadoudicko mamadoudicko temporarily deployed to preview September 21, 2023 15:51 — with GitHub Actions Inactive
@dosubot dosubot bot added the area: backend Related to backend functionality or under the /backend directory label Sep 21, 2023
@vercel
Copy link

vercel bot commented Sep 21, 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 Sep 22, 2023 7:33am
quivr-strapi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2023 7:33am
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2023 7:33am

@github-actions
Copy link
Contributor

github-actions bot commented Sep 21, 2023

Risk Level 2 - /home/runner/work/quivr/quivr/frontend/lib/api/subscription/subscription.ts

The code changes seem to be well-structured and follow the SOLID principles. However, there is a TODO comment about renaming 'rights' to 'role' in the Backend and using 'InvitationBrain' instead of 'BackendInvitationBrain'. This indicates that there might be some confusion or inconsistency in the naming conventions used in the code. It's recommended to address this TODO comment to improve the readability and maintainability of the code.


Risk Level 2 - /home/runner/work/quivr/quivr/frontend/app/brains-management/[brainId]/components/BrainManagementTabs/BrainManagementTabs.tsx

The code seems to be well written and follows good practices. However, there are a few areas that could be improved for better readability and maintainability:

  1. The BrainManagementTabs component is quite large and contains a lot of logic. Consider breaking it down into smaller, more manageable components.

  2. The isUserBrainOwner function is being used to determine if the current user is the owner of the brain. This could potentially be moved to a higher level in the component tree and passed down as a prop to avoid unnecessary computations.

  3. The isPublicBrain and hasEditRights variables are being calculated every time the component re-renders. Consider using the useMemo hook to memoize these values and improve performance.

Example:

const isPublicBrain = useMemo(() => brain?.status === \"public\", [brain]);
const hasEditRights = useMemo(() => !isPublicBrain || isCurrentUserBrainOwner, [isPublicBrain, isCurrentUserBrainOwner]);

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

The code changes are generally good, but there are a few areas that could be improved for better readability and maintainability.

  1. The invite_users_to_brain function has been modified to include a check for owner rights when assigning owner permissions. This is a good addition, but it would be better to separate this into a different function for better readability and separation of concerns. For example:
def validate_owner_rights(brain_id: UUID, current_user: UserIdentity, rights: str):
    if rights == \"Owner\":
        try:
            validate_brain_authorization(brain_id, current_user.id, RoleEnum.Owner)
        except HTTPException:
            raise HTTPException(status_code=403, detail=\"You don't have the rights to give owner permissions\")

Then in invite_users_to_brain:

validate_owner_rights(brain_id, current_user, subscription.rights)
  1. The subscribe_to_brain_handler function has been added. This is a good addition, but it would be better to separate the checks for brain existence, public status, and existing subscription into different functions for better readability and separation of concerns. For example:
def check_brain_exists(brain_id: UUID):
    brain = get_brain_by_id(brain_id)
    if brain is None:
        raise HTTPException(status_code=404, detail=\"Brain not found\")

def check_brain_public(brain_id: UUID):
    brain = get_brain_by_id(brain_id)
    if brain.status != \"public\":
        raise HTTPException(status_code=403, detail=\"You cannot subscribe to this brain without invitation\")

def check_already_subscribed(brain_id: UUID, current_user: UserIdentity):
    user_brain = get_brain_for_user(current_user.id, brain_id)
    if user_brain is not None:
        raise HTTPException(status_code=403, detail=\"You are already subscribed to this brain\")

Then in subscribe_to_brain_handler:

check_brain_exists(brain_id)
check_brain_public(brain_id)
check_already_subscribed(brain_id, current_user)

📚🔍🔄


Powered by Code Review GPT

@gozineb gozineb merged commit 2c9a0c1 into main Sep 22, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend Related to backend functionality or under the /backend directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants