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

Add correct verbose_name and verbose_name_plural to Audio, DeletedAudio, and SensitiveAudio models #4986

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

dryruffian
Copy link
Contributor

@dryruffian dryruffian commented Sep 25, 2024

Fixes

Fixes #4655 by @dhruvkb

Description

This PR addresses the issue of missing or incorrect verbose_name and verbose_name_plural values for audio-related models. The changes improve the Django admin interface experience by providing more accurate and consistent labeling for these models, as specified in the issue description.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (ov just catalog/generate-docs media-props
    for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@dryruffian dryruffian requested a review from a team as a code owner September 25, 2024 14:41
@dryruffian dryruffian requested review from krysal and sarayourfriend and removed request for a team September 25, 2024 14:41
@openverse-bot openverse-bot added 🧱 stack: api Related to the Django API 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 📄 aspect: text Concerns the textual material in the repository 💻 aspect: code Concerns the software code in the repository labels Sep 25, 2024
krysal
krysal previously requested changes Sep 25, 2024
Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

This is looking good. For tests to pass you just need to generate and include the migrations associated to these changes that Django creates. Run the following and commit the changes:

  1. ov just api/dj makemigration
  2. ov just api/dj migrate

The migration would be no-op, you can check doing ov just api/dj sqlmigrate api 0071, but they are still required.

Expected output
BEGIN;
--
-- Change Meta options on audio
--
-- (no-op)
--
-- Change Meta options on deletedaudio
--
-- (no-op)
--
-- Change Meta options on sensitiveaudio
--
-- (no-op)
COMMIT;

@dryruffian dryruffian requested a review from a team as a code owner September 25, 2024 16:32
@dryruffian dryruffian requested review from dhruvkb and removed request for a team September 25, 2024 16:32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This Change can fix issue #4974

Copy link
Contributor

Choose a reason for hiding this comment

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

The overall fix required broader changes, which I've got in this PR: #4992

You can rebase this PR on that one, or wait for that one to be merged (hopefully it will go in soon given the criticality of it to the development environment).

@dryruffian
Copy link
Contributor Author

Hi @krysal,
Thank you for the suggestion. I've made the suggested changes. Please review my PR and let me know if you have any further suggestions.

Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This LGTM, I'll go ahead and removed the change to the env.docker file in favour of #4992 which has a broader fix and then merge.

operations = [
migrations.AlterModelOptions(
name='audio',
options={'ordering': ['-created_on'], 'verbose_name': 'audio track', 'verbose_name_plural': 'audio tracks'},
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what introduced this ordering change? 🤔 And why it wasn't present before. Image has had it since migration 0.

docker/es/env.docker Outdated Show resolved Hide resolved
@sarayourfriend
Copy link
Contributor

@dryruffian I've rebased your branch to try to fix that failing API test.

@sarayourfriend
Copy link
Contributor

sarayourfriend commented Sep 26, 2024

~@dhruvkb would you be able to lend a hand with debugging why the permission group might not be available in load_sample_data? I can't make out any reason why this PR should have any effect on that 🤔 ~

Never mind! @dryruffian you'll need to update the load_sample_data script to use the new correct names of the models when identifying the permission groups.

In fact, however, I am worried that this will break existing permissions in production. @dhruvkb can you help review this and see whether it will cause a problem downstream if we change the verbose name of the model? IIRC we have code that manually builds the permission checks in the media moderation admin.

@dryruffian
Copy link
Contributor Author

Thanks @sarayourfriend,
I will add the suggested changes

@dryruffian
Copy link
Contributor Author

dryruffian commented Sep 26, 2024

Hi @sarayourfriend,
I've run ov just api/init on my local machine, and it's working fine. However, the API test is failing in a similar stage, and I don't know why. The "Migration Safety Check / Check and Apply Labels" (pull request) is failing. Can you please help me troubleshoot this?

@sarayourfriend
Copy link
Contributor

Yes, as I said, because this PR changes the name of the model, the name of the permission is no longer the same as it was before.

We can fix this by using a part of the permission object that is constant, the codename. Here is a diff to apply to do that:

diff --git a/load_sample_data.sh b/load_sample_data.sh
index cd5f195a3..a67d3b4c4 100755
--- a/load_sample_data.sh
+++ b/load_sample_data.sh
@@ -101,9 +101,9 @@ if created:
   print('Setting up Content Moderators group')
   for model, perms in model_perms_map.items():
     for perm in perms:
-      name = f'Can {crud_perm_map[perm]} {model}'
+      name = f'{crud_perm_map[perm]}_{model}'
       print(f'Adding permission to moderators group: {name}')
-      model_add_perm = Permission.objects.get(name=name)
+      model_add_perm = Permission.objects.get(codename=name)
       mod_group.permissions.add(model_add_perm)
   mod_group.save()
   mod_group.user_set.add(User.objects.get(username='moderator'))

@sarayourfriend
Copy link
Contributor

You can ignore the failure on the migration safety warning; it will not complete on forks. It isn't a required request, so don't worry about it, it won't block merging the PR.

@dryruffian
Copy link
Contributor Author

Hi @dhruvkb, I've fixed all the tests in this PR. Please review my changes and let me know if you have any further suggestions.

@openverse-bot openverse-bot added the migrations Modifications to Django migrations label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 📄 aspect: text Concerns the textual material in the repository 🛠 goal: fix Bug fix migrations Modifications to Django migrations 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API
Projects
Status: ✅ Approved
Development

Successfully merging this pull request may close these issues.

Normalise verbose_name and verbose_name_plural for audio models
4 participants