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: allow user to unsubscribe from a brain #1254

Merged
merged 7 commits into from
Sep 25, 2023
Merged

Conversation

mamadoudicko
Copy link
Contributor

@mamadoudicko mamadoudicko commented Sep 25, 2023

  • update translations
  • add
  • update tests
  • redirect to /brains-management on invalid brain id
  • refactor: move delete_brain_user to delete_brain_users
  • add /POST '/brains/{brain_id}/subscribe'
  • handle public brain unsubscription

#1212

@vercel
Copy link

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

@dosubot dosubot bot added the area: backend Related to backend functionality or under the /backend directory label Sep 25, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 25, 2023

Risk Level 2 - /home/runner/work/quivr/quivr/backend/models/databases/supabase/brains.py

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

  1. In the delete_brain_user_by_id method, the results variable is not used after being assigned. If the result of the delete operation is not needed, you can remove this assignment.

  2. The delete_brain_vector and delete_brain_users methods have inconsistent return types. The former does not return anything, while the latter returns the result of the delete operation. It would be better to make these consistent, either by returning the result in both methods or in neither.

Here are the suggested changes:

# Suggested change for delete_brain_user_by_id
self.db.table(\"brains_users\")
.delete()
.match({\"brain_id\": str(brain_id), \"user_id\": str(user_id)})
.execute()

# Suggested change for delete_brain_vector
return self.db.table(\"brains_vectors\")
.delete()
.match({\"brain_id\": brain_id})
.execute()

Risk Level 2 - /home/runner/work/quivr/quivr/backend/models/brains.py

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

  1. The delete_brain method has a high cyclomatic complexity due to the nested if-else condition. Consider simplifying this method to improve readability and maintainability.

  2. The openai_api_key attribute in the Brain class is a potential security risk if it is not properly managed. Ensure that this attribute is securely stored and not exposed in any logs or error messages.

  3. The get_brain_users and delete_user_from_brain methods have a # TODO comment to move them to a new BrainService. Consider doing this to adhere to the Single Responsibility Principle.

  4. The get_unique_brain_files and get_all_knowledge_in_brain methods seem to have duplicate code. Consider refactoring these methods to remove the duplication.

Example:

    def get_unique_brain_files(self):
        self.files = self._get_files()
        return self.files

    def get_all_knowledge_in_brain(self):
        self.files = self._get_files()
        return self.files

    def _get_files(self):
        vector_ids = self.supabase_db.get_brain_vector_ids(self.id)  # type: ignore
        return get_unique_files_from_vector_ids(vector_ids)

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

The code is generally well written, but there are a few areas where improvements could be made for readability and maintainability. For example, the handleUnsubscribeOrDeleteBrain function is quite large and complex, which could make it difficult to understand and maintain. Consider breaking this down into smaller, more manageable functions.


📚🔐🔄


Powered by Code Review GPT

"deleteConfirmYes": "Oui, supprimer",
"returnButton": "Retour",
"unsubscribeButton": "Se désabonner du cerveau",
"unsubscribeConfirmQuestion": "Êtes-vous sûr de vouloir vous désabonner de ce cerveau ? Cette action ne peut pas être annulée.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ca fait bizarre "cette action ne peut pas etre annulée" vu que tu peux juste repartir t'abonner au cerveau

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🚮

gozineb
gozineb previously approved these changes Sep 25, 2023
@mamadoudicko mamadoudicko merged commit 1643b54 into main Sep 25, 2023
10 of 12 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.

None yet

2 participants