Skip to content

feat: cap role description length and update timestamp on permission drops - #679

Open
wgu-taylor-payne wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:tpayne/issue-667-role-description-cap
Open

wgu-taylor-payne wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:tpayne/issue-667-role-description-cap

Conversation

@wgu-taylor-payne

@wgu-taylor-payne wgu-taylor-payne commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the #647 review. Closes #667.

Problem

  • The custom role description had no length limit, so the API accepted a 10,000+ character value.
  • load_authz_schema --drop-custom-role-permissions removed grants from custom roles without touching the role row. updated_at stayed stale, so GET /roles/ sorted those roles as if they had not changed. ADR 0036 treats a permission change as a change to the role.

Changes

  • Description limit: CreateCustomRoleSerializer and UpdateCustomRoleSerializer cap description at 500 characters, and the API docs note the limit. The longest existing role description is 201 characters.
  • Timestamp on dropped grants: SchemaApplier._drop_unlinked_custom_grants collects the roles that lose a grant and sets their updated_at with one UPDATE ... SET updated_at = NOW(). It uses Now() because auto_now does not fire on QuerySet.update(). The update runs inside the same apply transaction as the grant deletion, and roles that keep all their grants are left alone.

Testing

  • REST tests for create (POST) and edit (PATCH): a 500-character description is stored, and a 501-character description returns 400 with the role unchanged.
  • Schema apply test: after a drop, the role that lost a grant has a newer updated_at, and a second custom role whose grants all stay keeps its old timestamp.
  • Mutation-checked: removing max_length or the updated_at update makes the matching tests fail.

Manual check:

  1. POST /api/authz/v1/roles/ with a 501-character description: expect 400 naming description.
  2. Give a custom role a permission, remove that permission from the schema, and run load_authz_schema --drop-custom-role-permissions. The role's updated_at in GET /api/authz/v1/roles/ should advance.

Rollback

Revert this commit. There are no migrations. Descriptions stored before the revert stay valid either way.

Merge checklist:

  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

AI Usage

Kiro was used to aid development and testing.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Dec 3, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @wgu-taylor-payne!

This repository is currently maintained by @openedx/committers-openedx-authz.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Regression tests do not cover the POST/PATCH description limits or verify that grant drops advance timestamps only for affected custom roles.

2 open issues
What changed in this PR

Addresses #667’s follow-up to #647 by tightening custom-role validation and keeping role timestamps current after permission drops.

Changes:

  • Limits descriptions to 500 characters on create and update.
  • Updates affected roles’ updated_at using database time when schema application drops grants.
File Description
src/​openedx_authz/​rest_api/​v1/​serializers.py Adds description limits to both serializers.
src/​openedx_authz/​engine/​renderer.py Refreshes timestamps for roles whose grants are dropped.

Review effort: Balanced

Comment thread src/openedx_authz/engine/renderer.py Resolved
@wgu-taylor-payne
wgu-taylor-payne force-pushed the tpayne/issue-667-role-description-cap branch from 898089e to 104e051 Compare December 3, 2026 21:54
…drops

Addresses issue openedx#667 (follow-up from PR openedx#647 review):

1. Cap role description length at 500 characters in both CreateCustomRoleSerializer
   and UpdateCustomRoleSerializer. The field previously had no max length; a 10k+
   character value was accepted during review. The longest existing role description
   is 201 characters, so 500 is a reasonable limit.

2. Update custom role updated_at timestamp when load_authz_schema --drop-custom-role-permissions
   removes grants. Previously the command deleted permission grants without touching
   the role row, so updated_at stayed old and GET /roles/ sorted by a stale timestamp.
   Per ADR 0036, permission changes should update the role's timestamp.

Closes openedx#667

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@rodmgwgu rodmgwgu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, looking good, just a couple of nits to discuss.


display_name = StrictCharField()
description = serializers.CharField(required=False, default="", allow_blank=True)
description = serializers.CharField(required=False, default="", allow_blank=True, max_length=500)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we also enforce this limit at the python API level at create_custom_role and update_custom_role in api/custom_roles.py? what do you think?

FIXED_FIELDS = ("display_name", "scope_types")

description = serializers.CharField(required=False, allow_blank=True)
description = serializers.CharField(required=False, allow_blank=True, max_length=500)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, should we make this 500 a constant to avoid repeating it several times?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Cap role description length and update role updated_at when custom-role permissions are dropped

4 participants