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

Adding missing help_text and check #647

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

john-westcott-iv
Copy link
Member

This adds a help_text check, validating that every model has all of its help_text defined.

It also addresses missing help_text from existing models.

name = models.CharField("name", max_length=255)
content_type = models.ForeignKey(ContentType, models.CASCADE, verbose_name="content type")
codename = models.CharField("codename", max_length=100)
name = models.CharField("name", max_length=255, help_text=_("The name of this permission."))
Copy link
Member

Choose a reason for hiding this comment

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

You'll find that in a lot of these, they are not exposed in the API.

This model is also a mirror of auth.Permission so why doesn't it have help_text? Because the model it mirrors doesn't have help text.

The permission name is more of a python / admin pages display oriented thing. Hopefully we don't ever use it. If you wanted to get more specific about that, you could. Again, it shouldn't be outward API-facing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I take the help_text off these and add them to the .help_text.ignore file or just leave it on for now?

Copy link
Member

Choose a reason for hiding this comment

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

The permission model, itself, maybe one day (soon-ish) be surfaced in the API in a read-only way. So it might be good to have these, although I realize I probably just have to make a PR.

Copy link
Contributor

@BrennanPaciorek BrennanPaciorek Nov 18, 2024

Choose a reason for hiding this comment

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

I don't see much purpose in dropping the help_text and making an ignore here, so I think we should keep this one, save us an extra migration if or when this gets exposed to the API.

content_type = models.ForeignKey(ContentType, models.CASCADE, verbose_name="content type")
codename = models.CharField("codename", max_length=100)
name = models.CharField("name", max_length=255, help_text=_("The name of this permission."))
content_type = models.ForeignKey(ContentType, models.CASCADE, verbose_name="content type", help_text=_("The content type this permission will apply to."))
Copy link
Member

Choose a reason for hiding this comment

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

Let's say we have a permission statement "John can pet the dog named Fido". That would be an instantiation of Permission (note that a permission entry it not an instantiation), the content type of the permission being dog.

Copy link
Member

Choose a reason for hiding this comment

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

Writing more comments further down, I realize "subject" is a hazardous word. "object" might be better. English SVO grammar structure would imply "subject" is what is referred to as "actor" elsewhere.

codename = models.CharField(
"codename",
max_length=100,
help_text=_("The name of the permission, giving the action and the model, from the Django Permission model."),
Copy link
Member

Choose a reason for hiding this comment

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

This is the only one that matters, and unfortunately, you can't say the format rule always applies, but this does conform to the existing Django auth app pattern.

So the format of the permission is usually in the form of {action}_{model_name}, but can be customized for a specific entry in a model's Meta class. The model name is well-defined formally, and the action is usually / probably the DRF viewset action. This is actually under-specified and in some internal Django uses the actually unique combination of (app_label, model_name, action) is used. But in DAB RBAC, it is expected to be unique without app_label, due to additional enforcement.

Copy link
Member Author

Choose a reason for hiding this comment

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

How does this sound?

The name of the permission. This is in the format {action}_{model_name}. Where action is typically the view set action (view/list/etc) from Django rest framework. 

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we would want to call this The name of the permission.... because that is the text used for name on line 33.
As to the comment about the format, we should only include the format if the model class itself sets format.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tznamena Good callout

Copy link
Contributor

@BrennanPaciorek BrennanPaciorek left a comment

Choose a reason for hiding this comment

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

More migrations appear to be necessary.

check: exit 1 (1.02 seconds) /home/runner/work/django-ansible-base/django-ansible-base> python3 manage.py makemigrations --check

The other comments are just recommendations and lightly-held opinions.

ansible_base/activitystream/models/entry.py Outdated Show resolved Hide resolved
ansible_base/activitystream/models/entry.py Outdated Show resolved Hide resolved
name = models.CharField("name", max_length=255)
content_type = models.ForeignKey(ContentType, models.CASCADE, verbose_name="content type")
codename = models.CharField("codename", max_length=100)
name = models.CharField("name", max_length=255, help_text=_("The name of this permission."))
Copy link
Contributor

@BrennanPaciorek BrennanPaciorek Nov 18, 2024

Choose a reason for hiding this comment

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

I don't see much purpose in dropping the help_text and making an ignore here, so I think we should keep this one, save us an extra migration if or when this gets exposed to the API.

Copy link

sonarcloud bot commented Nov 22, 2024

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.

5 participants