Skip to content

Conversation

@zackkrida
Copy link
Member

This experimental PR adds a user data type to Mathesar. This PR should be considered a proof-of-concept but also contains code sufficient for review and production use. We may wish to split this into multiple PRs for easier review, when we're ready. It's already split by commits, one for:

  • backend changes
  • ui changes
  • docs

I'm publishing this draft now so an interested user can review this feature and provide feedback. This is not ready for full review by the team.

This PR will be updated with a more detailed technical description when it is ready for full review.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added 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.

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.

zackkrida and others added 4 commits November 21, 2025 09:58
- Add user_type metadata field to ColumnMetadata model
- Add user type column handling in RPC endpoints (columns, records, forms)
- Add user display utilities for formatting user data
- Add migration for user_type column metadata
- Make user_display_field nullable to match pattern of other type-specific fields
- Add UserCell, UserInput, and UserFilterInput components
- Add user type to abstract type system and type definitions
- Add user type column display options (username, display name, email)
- Add user type filtering support
- Add user type default value options (auto-set to editor, default user)
- Prevent user type columns from being added to forms
- Add user utilities for fetching and displaying users
- Add comprehensive user type guide with examples
- Add user type images for documentation
- Update data types documentation to include user type
@zackkrida
Copy link
Member Author

@mathemancer please review the backend implementation in 6c34b8c (#4997).

Regarding the frontend, I need to compare this to some overlapping work in cross-table editing to validate the approach, and make this a bit easier to review for the frontend team before getting frontend review.

Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

Partial review so you have stuff to think about:

  • Please avoid hiding the mutation of python objects in function calls, as you do in _add_user_display_values_to_record_info et al. I'd really prefer the modifications be inline where they're clearly visible; see the addition of download_links for example.
  • You need to refactor this so that a given RPC call never generates multiple requests for the same Django model object. For example, records.add calls get_columns_meta_data in both _set_last_edited_by_columns and _add_user_display_values_to_record_info. The problem is also present in records.list since both get_download_link_columns and _add_user_display_values_to_record_info call the get_columns_meta_data function. We either need to cache that metadata getting function for the duration of a request, or (easier) just call it in the main rpc function body then use it where needed.

More to come later; late for the team event!

max_length=50,
null=True
)
user_last_edited_by = models.BooleanField(default=False, null=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this name really confusing. What about track_editing_user?

duration_min: Optional[str]
duration_max: Optional[str]
display_width: Optional[int]
file_backend: Optional[str]
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, nice catch

display_width: Optional[int]
file_backend: Optional[str]
user_type: Optional[bool]
user_display_field: Optional[Literal["full_name", "email", "username"]]
Copy link
Contributor

Choose a reason for hiding this comment

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

If user_display_field is optional, I guess I don't see why user_type is needed. If this is non-null, then display the column as specified, otherwise, just display as an integer.

If you really really want to keep user_type, I don't think that should be optional since it's always either true or false. Just use false for the default.

file_backend=model.file_backend,
user_type=model.user_type,
user_display_field=model.user_display_field or "username",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think user_last_edited_by is missing here.

Comment on lines +417 to +419
from modernrpc.core import REQUEST_KEY
request = kwargs.get(REQUEST_KEY)
user = request.user if request else None
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Why are you reimporting REQUEST_KEY?
  • This isn't going to be called without a request, right? If not, there's way too much logic here.

Comment on lines +346 to +354
table_oid: int,
database_id: int,
limit: int = None,
offset: int = None,
order: list[OrderBy] = None,
filter: Filter = None,
grouping: Grouping = None,
return_record_summaries: bool = False,
**kwargs,
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like your editor really hates the double-indent function args style, but I prefer it. This comment is applicable to many of your PRs (maybe all)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'll disable automatic formatting in vscode for Mathesar. Preferences aside it clutters the diffs too much anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'll disable automatic formatting in vscode for Mathesar. Preferences aside it clutters the diffs too much anyway.

"""
user = kwargs.get(REQUEST_KEY).user
# Automatically set user_last_edited_by columns to current user ID
_set_last_edited_by_columns(record_def, table_oid, database_id, user.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in a separate module, and should not modify records in place.

or None
)

_add_user_display_values_to_record_info(record_info, table_oid, database_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in a separate module, and should not modify in place.

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