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 an Organization entity type with a Farm bundle #849

Draft
wants to merge 29 commits into
base: 3.x
Choose a base branch
from

Conversation

mstenta
Copy link
Member

@mstenta mstenta commented May 29, 2024

For discussion see: https://farmos.discourse.group/t/organization-level-data/2003

This adds a new "Organization" (organization) entity type to farmOS for storing organization-level data. Organization entities have the following base-fields (similar to plan entities, with an additional user field):

  • Data
  • Notes
  • Files
  • Images
  • Users

The "Users" (user) field allows users a group to reference one or more user accounts that are associated with it. This does not serve any purpose other than informational at this point, but could be used in the future for building additional UX and/or access control features on top of.

An initial "Farm" (farm) bundle of the Organization entity is provided as a way of representing "farm organizations". Farm organizations do not have any bundle-specific fields on them at this point, but new ones could be considered in the future. Contrib modules will also be able to add their own for specific purposes.

A farm organization reference base field is added to all assets for associating them with a farm organization entity.

This is still just a draft to get things started. The initial data architecture is ready for review, and some minimal UI elements are added. More UI/UX is needed to make this usable from the frontend. Potential next steps (for this PR):

  • Add a tab to view all assets in a farm.
  • Add support for filtering assets by farm.
  • Allow setting farm via asset CSV import.
  • Include farm in asset CSV exports.
  • Add a bulk action for assigning assets to a farm.
  • Add support for filtering location hierarchy by farm.
  • ...?

We are also discussing adding a telephone and address field to organization entities (or just farm bundles). That is not done yet in this PR (pending community feedback in the forum discussion linked above).

@paul121
Copy link
Member

paul121 commented Jul 11, 2024

Added a few commits in my branch: https://github.com/paul121/farmOS/tree/3.x-organization

@paul121
Copy link
Member

paul121 commented Jul 11, 2024

Added an "Assets" view + tab in my branch:
Screenshot from 2024-07-11 11-04-52

@paul121
Copy link
Member

paul121 commented Jul 11, 2024

Add support for filtering assets by farm.

Because the asset.farm field is a bundle field, this is working on the by_type asset pages but not the "All assets" page. I'm not sure the best way to include this on the "All assets" page.

There's a good amount of logic in our farm_ui_views_add_bundle_handlers() function that would be ideal to re-use. I feel like we should refactor this and/or add another helper function that allows adding a single bundle field handler when needed... _add_bundle_field_handler($field_name, ...). We could add a case for the "All assets" view in farm_ui_views_views_pre_render and use this function to add just the asset.farm filter. I also think this helper function could be useful in other contexts (allow any module to add their own bundle field to asset/log views)

I think the alternative is hard-coding some of this for only the asset.farm field on this single view, but even then I feel like we'll end up duplicating existing logic to load the views data table name, handler settings, etc. Thus maybe we take a step and refactor the existing function... hmm..

@mstenta
Copy link
Member Author

mstenta commented Jul 12, 2024

Added a few commits in my branch: https://github.com/paul121/farmOS/tree/3.x-organization

Thanks @paul121 - these look great! I merged them into the PR.

I added an additional commit to remove roles from Views remember_roles config. There were a couple in this PR, but also some in other farmOS Views, so I just did it all in a single commit.

@mstenta
Copy link
Member Author

mstenta commented Jul 12, 2024

@paul121 and I just discussed in chat and agreed that farm should be a base field, not a bundle field. I pushed a commit to change it.

This avoids the current issue with bundle fields not allowing writes via the API: https://www.drupal.org/project/farm/issues/3314741

However, this means that the farm field will not be automatically added to things like Views and CSV importers and exporters. This might require refactoring the logic in farm_ui_views, farm_import_csv, and farm_export_csv (maybe others) to add support for base fields, which could be done in a separate PR as a prerequisite for this one. I will update the description above to make note of that.

@mstenta mstenta force-pushed the 3.x-organization branch 2 times, most recently from 7eda625 to 27fb452 Compare July 25, 2024 16:17
@mstenta
Copy link
Member Author

mstenta commented Jul 29, 2024

Pushed a commit that adds organization entity support in the farm_role module. Otherwise the default permissions for creating organizations are not added to roles. We may want to consider changing some of the defaults for this (eg: should farm_worker be able to create/edit orgs? maybe not.)

This was cloned directly from the asset module, with no other
modifications, using the following commands:

cp -r modules/core/asset/ modules/core/organization
find modules/core/organization -depth -exec rename 's/asset/organization/g' {} \;
find modules/core/organization -depth -exec rename 's/Asset/Organization/g' {} \;
find modules/core/organization -type f -exec sed -i 's/asset/organization/g' {} +
find modules/core/organization -type f -exec sed -i 's/Asset/Organization/g' {} +
- Use statements should be sorted alphabetically
- Line exceeds 80 characters
This was copied from the asset module, which required a
migration path from Drupal 7. The new organization entities
did not exist on Drupal 7 so they don't need a migration path.
These are remnants of the farmOS v2 branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants