Skip to content

Flag and FlagEntity Model Draft #1269

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 7 commits into from
May 26, 2025
Merged

Conversation

sh-ran
Copy link
Collaborator

@sh-ran sh-ran commented May 17, 2025

Contributor checklist


Description

This is a just a draft for Flag and FlagEntity model, viewsets and serializers.

Related issue

Copy link

netlify bot commented May 17, 2025

Deploy Preview for activist-org ready!

Name Link
🔨 Latest commit 151a94d
🔍 Latest deploy log https://app.netlify.com/projects/activist-org/deploys/683439c72a2ac200091ac195
😎 Deploy Preview https://deploy-preview-1269--activist-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Thank you for the pull request! ❤️

The activist team will do our best to address your contribution as soon as we can. If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. Also consider attending our bi-weekly Saturday developer syncs! It'd be great to meet you 😊

Copy link
Contributor

github-actions bot commented May 17, 2025

Maintainer Checklist

The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

  • The TypeScript, pytest and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The Playwright end to end and Zap penetration tests have been ran and are passing (if necessary)

  • The changelog has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

@andrewtavis
Copy link
Member

Realizing that I didn't get back to you on the Figma question, @sh-ran! Sorry about that! Has been a busy week with work and a presentation I needed to give for this and the other community I work in 😊 Let's touch base on this and try to bring it in soon :) Thank you for your efforts! 🚀

@andrewtavis andrewtavis requested review from andrewtavis and to-sta May 17, 2025 11:54
@sh-ran
Copy link
Collaborator Author

sh-ran commented May 17, 2025

No worries @andrewtavis I realized that when I saw the matrix post and tried to figure out whatever I can. Decided to send this PR so we can discuss and talk about the changes tonight in the dev sync.

@andrewtavis
Copy link
Member

@to-sta, pinging you here for support for @sh-ran as we're not sure exactly where to go here :) Copying over the points from the dev sync summary:

For the flag model...

  • Users should be able to flag content on the platform that would then be fed to admins and staff
    • The Figma schema for the table can be found here, but needs to be updated
    • We're not sure if we want to maintain a single flag table or separate ones for each entity like organization_flag, group_flag, etc
    • The resulting workflow for this for people checking things does need to be unified

Do you have any suggestions here?

@to-sta
Copy link
Collaborator

to-sta commented May 19, 2025

@to-sta, pinging you here for support for @sh-ran as we're not sure exactly where to go here :) Copying over the points from the dev sync summary:

For the flag model...

  • Users should be able to flag content on the platform that would then be fed to admins and staff
    • The Figma schema for the table can be found here, but needs to be updated
    • We're not sure if we want to maintain a single flag table or separate ones for each entity like organization_flag, group_flag, etc
    • The resulting workflow for this for people checking things does need to be unified

Do you have any suggestions here?

I think splitting it up is a good idea and then I would a add One-to-Many relationship with e.g. Org and User.

Then we can retrieve the related information and check the permissions within the API (admin,...).

@andrewtavis
Copy link
Member

So there wouldn't be a flag table, and we'd need to then eventually combine these tables in the interface for admins to deal with? Or within admin views would we always filter by the different entities? I guess maybe that would be fine and they could just see notification icons for the various entity types - so like "organizations has five orgs that need attention and groups has three groups that need attention" and they can select what they want to view?

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 20, 2025

So we are using the same models as in figma but we are just flagging everything separate and then creating a table with one-to-many relationship? If that's the case, I'll get to working on it now!

Thank you @to-sta and @andrewtavis

@andrewtavis
Copy link
Member

No the Figma models need to change, @sh-ran :) I can get to that later. We'd have organization_flag, group_flag, etc :) It'd function like other sub tables, and we'd just have foreign keys to user ids and the entity id given the table - org_id for organization_flag, etc.

We're basically doing away with the idea of a unified flag dashboard and more separate dashboards based on entity types, which likely will be easier to work with anyway 😊

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 20, 2025

something like this? Sorry for bombarding with these many questions.

image

@andrewtavis
Copy link
Member

No need to apologize! Thank you for asking so many questions 😊 That looks good to me! If someone removes the flag of the entity, then we can just remove the entry as I don't think we need to collect data on whether someone has flagged something and decided against it.

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 20, 2025

If you don't mind, I could write some code up for the organization part and maybe you and tobi can both review and suggest changes as needed.

@andrewtavis
Copy link
Member

Sounds perfect! Thanks so much, @sh-ran! 😊

her: "I'm complicated"
me: "I resolve git conflicts"

Jokes aside current commit has code for organization_flags.
Models, Viewsets, Serializers, Factories and tests are all included and working perfectly.
@andrewtavis
Copy link
Member

For me the current rendition looks great 😊 I think you can proceed to the other flaggable entities and then we can do the final review when the rest are in :) Thanks, @sh-ran!

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 21, 2025

Thank you @andrewtavis

Will be sending the remaining PR's ASAP 😄

Comment on lines 60 to 70
class OrganizationFlag(models.Model):
"""
Model for flagged organizations.
"""

id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
flagged_org_id = models.ForeignKey(
"communities.Organization", on_delete=models.CASCADE
)
flagger_id = models.ForeignKey("authentication.UserModel", on_delete=models.CASCADE)
flagged_on = models.DateTimeField(auto_now=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Django automatically appends _id to foreign key fields at the database level, so something like flagger_id would become flagger_id_id. To avoid this confusion and improve consistency, let's rename the field to flagged_by, which aligns better with our existing field created_by.

Additionally, let's update the flagged_on field to created_at for consistency with how we name timestamp fields throughout the project.

Since this is a many-to-many relationship with extra fields, we should use Django’s ManyToManyField along with the through keyword.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I shall read through the docs and figure out how to fix it. Thank you @to-sta

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 23, 2025

Hello @to-sta

So i made the changes as you had suggested although I am a bit skeptical about if what I have submitted is correct. I had to change the tests as well as i was getting an error with regards to ManyToMany fields saying I had to use .set() I couldnt understand what was going wrong apart from it being in the Factories part of the code. I had to comment out that part in order to get the tests to work (ik that is not the right way of doing it but i had no idea what else to do 😅 ).

For reference of through key I used this from the docs:

image

@andrewtavis
Copy link
Member

Quick note via our discussion: We need to update the schemas on Figma before this is merged :) Please let's remember this 😊

@andrewtavis
Copy link
Member

Nice that the tests are passing, @sh-ran! So from here we expand this to groups and events, right? Or is there something more that needs to be added in before it's propagated to other entities?

@sh-ran
Copy link
Collaborator Author

sh-ran commented May 26, 2025

Yup pretty much it for this PR.

I am almost done with the groups and will be sending in the PR later this evening. I was wondering if there will be any merge conflicts between the two as we have made changes to a few of the same files?

Just wanted to mention that there is a small bug in the delete test about which @to-sta and I discussed yesterday. We couldn't figure out what was causing it. I tried digging through the codebase last night but couldn't find anything helpful. For now I have excluded the 403 part of the test and will get back to it once I start writing the tests again. I'll be excluding that part in the next few PR's as well. Just a heads up.

@andrewtavis
Copy link
Member

All sounds good, @sh-ran! We'll finalize the review and bring this in soon, and if there are any conflicts with groups we'll handle them with you 😊

@andrewtavis
Copy link
Member

Netlify is having some down time for deployment it seems given the error from main merging in. I'll check later and hopefully bring it in then :)

Copy link
Member

@andrewtavis andrewtavis left a comment

Choose a reason for hiding this comment

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

Netlify's up and running and all's looking great here, @sh-ran! Thanks for taking on the work here, @sh-ran, and for the collaboration, @to-sta! Looking forward to getting groups and events in and closing out the flags issue 🏁😊

@andrewtavis andrewtavis merged commit 3087780 into activist-org:main May 26, 2025
6 checks passed
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.

3 participants