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

[back] feat: add the EntityContext model #1844

Merged
merged 34 commits into from
Nov 30, 2023
Merged

Conversation

GresilleSiffle
Copy link
Collaborator

@GresilleSiffle GresilleSiffle commented Nov 16, 2023

related to #1852


Description

This PR replaces the poll.moderation system by EntitContext. A model used to represent a textual localized context related to one or more entities.

Those contexts can be enabled or disabled from the admin interface, and can target entities based on any of their metadata. All EntitContext related to an entity are returned by the views using the RecommendationSerializer. When its attribute unsafe is set to True, all related entities will be marked as unsafe.

Scope of this PR:

  • refactor the back end to use EntitContext instead of poll.moderation
  • make poll views return EntitContext (other views will be updated in following PRs)
  • make the analysis page display all EntityContext created by the association (other pages, like comparison will be updated in following PRs)

Out of scope:

  • refactor the comparison page
  • refactor the entity lists

capture

to-do

back end - model EntityContext

  • create the new models
    • delete the concept of source_url and source_label to simplify the model
    • delete the concept of origin?
  • create its admin interface
  • add the new translations

back end

  • tests
    • test the method poll.entity_has_unsafe_context
    • test the method poll.get_entity_contexts
    • test the method entity_poll_rating.unsafe_recommendation_reasons (update the existing tests)
    • test the new behaviours of the recommendations API

back end serializers

  • RecommendationSerializer should include the entity contexts

front end

  • display != messages when the context's origin is the contributors or the association

front end - analysis page

  • display the entity context
  • refresh the text of the entity contexts when the UI language changes

front end - recommendations

  • (out of scope) display a link to the context (check the miro brainstorm)

front end - comparison

  • (out of scope) display the context of each entity

Checklist

  • I added the related issue(s) id in the related issues section (if any)
    • if not, delete the related issues section
  • I described my changes and my decisions in the PR description
  • I read the development guidelines of the CONTRIBUTING.md
  • The tests pass and have been updated if relevant
  • The code quality check pass

@GresilleSiffle GresilleSiffle self-assigned this Nov 16, 2023
@GresilleSiffle GresilleSiffle added Backend Back-end code of Tournesol Frontend Front-end code of Tournesol labels Nov 16, 2023
except FAQEntry.answers.RelatedObjectDoesNotExist: # pylint: disable=no-member
return False
else:
if obj.answers.exists():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously this method was always returning True.

@@ -126,26 +125,52 @@ def get_user_proof(self, user_id: int, keyword: str):
signer = Signer(salt=f"{keyword}:{self.name}")
return signer.sign(f"{user_id:05d}")

def entity_in_moderation(self, entity_metadata) -> bool:
def entity_has_unsafe_context(self, entity_metadata) -> tuple:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's not forget to delete the field moderation in the next update.

@GresilleSiffle GresilleSiffle marked this pull request as ready for review November 27, 2023 13:58
@GresilleSiffle GresilleSiffle changed the title WIP / [back] feat: add the EntityContext model [back] feat: add the EntityContext model Nov 27, 2023
backend/backoffice/admin.py Show resolved Hide resolved
backend/tournesol/admin.py Outdated Show resolved Hide resolved
@GresilleSiffle GresilleSiffle merged commit fb6b330 into main Nov 30, 2023
8 checks passed
@GresilleSiffle GresilleSiffle deleted the back-add_entity_context branch November 30, 2023 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Back-end code of Tournesol Frontend Front-end code of Tournesol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants