Skip to content

Add users automatically to groups when created via api#6216

Closed
fthobe wants to merge 9 commits intosolidusio:mainfrom
S3-Store:25-add-users-automatically-to-groups-when-created-via-api
Closed

Add users automatically to groups when created via api#6216
fthobe wants to merge 9 commits intosolidusio:mainfrom
S3-Store:25-add-users-automatically-to-groups-when-created-via-api

Conversation

@fthobe
Copy link
Copy Markdown
Contributor

@fthobe fthobe commented Apr 10, 2025

Overview:

This pull request introduces functionality to automatically assign a user group to new users upon signup, based on the store's configuration. This enhancement allows for better user management and organization within the application by ensuring that users are categorized into appropriate groups from the moment they register.

Key Changes:

  1. User Group Assignment Logic:

    • Implemented the set_user_group method in the Spree::Api::UsersController. This method checks if the current store has the enforce_group_upon_signup setting enabled and assigns the default user group to new users accordingly.
  2. API Configuration Update:

    • Updated the user_attributes preference in Spree::ApiConfiguration to include :user_group_id. This change allows the user group information to be included in API responses for user details.
  3. Request Specs for User Group Assignment:

    • Added tests to the user request specs to verify the correct assignment of the default user group upon user creation. Scenarios were included to ensure that the user group is assigned when enforce_group_upon_signup is enabled and not assigned when it is disabled.
  4. Permitted Attributes Update:

    • Updated the @@user_attributes in Spree::PermittedAttributes to include :user_group_id, allowing the user group to be permitted during user creation and updates via the API.

Benefits:

  • Enhances user management by ensuring new users are automatically categorized into the appropriate user group.
  • Provides a more robust API response by including user group information.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@github-actions github-actions Bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem labels Apr 10, 2025
@fthobe fthobe changed the title 25 add users automatically to groups when created via api Add users automatically to groups when created via api Apr 10, 2025
Added associations in Spree::User model for user groups to support grouping users for targeted pricing and management.
Created Spree::UserGroup model with associations to users and stores to enable flexible user group management.
Updated locale files to include translations for user groups.
Added migrations to create spree_user_groups table and add user group references to users and stores.
- Added UserGroupsController to manage user groups.
- Created views for user group management, including:
  - New user group form (`new.html.erb`)
  - User group edit form (`edit.html.erb`)
  - User group index view (`index.html.erb`)
  - Partial view for user group form fields.
- Enhanced user management by allowing assignment of user groups to users in the user form.
- Updated store form to include a selection for the default cart user group.
- Added breadcrumb navigation for improved user experience in the admin panel.

This feature allows administrators to create, edit, and manage user groups, facilitating better organization and access control for users within the Spree application.
- Created a new users sub-menu partial to manage user-related navigation, including links to users and user groups.

These enhancements improve the organization of the admin interface, making it easier for administrators to manage user groups effectively.
- Updated UsersController to assign the default user group to new users if the current store has the `enforce_group_upon_signup` setting enabled.
- Added a checkbox in the store settings form to allow administrators to enable or disable the `enforce_group_upon_signup` feature.
- Included a new translation key for the `enforce_group_upon_signup` label in the English locale file.

This feature ensures that all new users are automatically added to a specified user group, improving user management and organization within the Spree application.
- Implemented the `set_user_group` method in `Spree::Api::UsersController`.
- This method assigns the default user group to a new user if the current store has the `enforce_group_upon_signup` setting enabled.
- Ensures that new users are automatically added to the specified user group during signup.
- Modified the `user_attributes` preference in `Spree::ApiConfiguration` to include `:user_group_id`.
- This change allows the user group information to be included in API responses for user details.
- Updated the user request specs to test the assignment of the default user group upon user creation.
- Added scenarios to verify that the user group is assigned when `enforce_group_upon_signup` is enabled and not assigned when it is disabled.
- Updated the `@@user_attributes` in `Spree::PermittedAttributes` to include `:user_group_id`.
- This allows the user group to be permitted during user creation and updates via the API.
@JustShah JustShah force-pushed the 25-add-users-automatically-to-groups-when-created-via-api branch from b19d82d to d6bea81 Compare April 10, 2025 14:37
@fthobe fthobe mentioned this pull request Apr 10, 2025
@fthobe fthobe closed this Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants