Skip to content

Commit

Permalink
Feature custom object keys (#157)
Browse files Browse the repository at this point in the history
* Added configuration for custom object keys

* Fixed mysql version in tests

* Updated UPGRADE.md

* Updated UPGRADE.md

* Updated docs

* Updated docs
  • Loading branch information
scrummer authored Jul 9, 2021
1 parent ce05805 commit 479cc26
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
MYSQL_DATABASE: dachcom_bundle_test
services:
mysql:
image: mysql:5.7
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: dachcom_bundle_test
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Verify MySql Connection
run: |
sudo apt-get update
sudo apt-get install -y mysql-client-5.7
sudo apt-get install -y mysql-client-8.0
mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES"
- name: Setup MySql
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
MYSQL_DATABASE: dachcom_bundle_test
services:
mysql:
image: mysql:5.7
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: dachcom_bundle_test
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Verify MySql Connection
run: |
sudo apt-get update
sudo apt-get install -y mysql-client-5.7
sudo apt-get install -y mysql-client-8.0
mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES"
- name: Setup MySql
Expand Down Expand Up @@ -124,4 +124,4 @@ jobs:
continue-on-error: true
run: |
bin/console cache:warmup --env=test
vendor/bin/ecs check src/MembersBundle --config easy-coding-standard.yml
vendor/bin/ecs check src/MembersBundle --config easy-coding-standard.yml
6 changes: 3 additions & 3 deletions .github/workflows/php-stan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
MYSQL_DATABASE: dachcom_bundle_test
services:
mysql:
image: mysql:5.7
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: dachcom_bundle_test
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Verify MySql Connection
run: |
sudo apt-get update
sudo apt-get install -y mysql-client-5.7
sudo apt-get install -y mysql-client-8.0
mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES"
- name: Setup MySql
Expand Down Expand Up @@ -122,4 +122,4 @@ jobs:
- name: Php Stan
run: |
bin/console cache:warmup --env=test
vendor/bin/phpstan analyse -c phpstan.neon -a tests/_phpstan-bootstrap.php src -l 2
vendor/bin/phpstan analyse -c phpstan.neon -a tests/_phpstan-bootstrap.php src -l 2
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ You need two classes: User and Group. So let's create it:
| Name | Field Type | Comment |
|---------------------|-------------|-------------------------------|
| userName | Input | |
| email | Input | **Note:** Do not add this field if you're using the [CMF](docs/20_CustomClassName.md). |
| email | Input | **Note:** Do not add this field if you're using the [CMF](docs/20_ClassCustomization.md). |
| confirmationToken | Input | must set to it read only |
| lastLogin | Date & Time | must set to it read only |
| password | Password | Hide it, if you want. **Note:** Do not add this field if you're using the [CMF](docs/20_CustomClassName.md). |
| password | Password | Hide it, if you want. **Note:** Do not add this field if you're using the [CMF](docs/20_ClassCustomization.md). |
| passwordRequestedAt | Date & Time | must set to it read only |
| groups | User Group | This field comes with Members |

> `membersUser` is the default name, you may want to change it. Read [here](docs/20_CustomClassName.md) how to achieve that.
> `membersUser` is the default name, you may want to change it. Read [here](docs/20_ClassCustomization.md) how to achieve that.

#### Customer Data Framework
If you want to use the [Customer Data Framework](https://github.com/pimcore/customer-data-framework) you need to do some further work. Read more about it [here](docs/300_CustomerDataFw.md).
Expand All @@ -113,7 +113,7 @@ You want to enable the SSO Feature in Members? Read more about it [here](./docs/
| name | Input | |
| roles | Multiselection | Set "Options Provider Class or Service Name" to `@MembersBundle\CoreExtension\Provider\RoleOptionsProvider` |

> `membersGroup` is the default name, you may want to change it. Read [here](docs/20_CustomClassName.md) how to achieve that.
> `membersGroup` is the default name, you may want to change it. Read [here](docs/20_ClassCustomization.md) how to achieve that.

Feel free to add additional fields since those are just the required ones. That's it. Members will use those classes to manage authentication and group management.

Expand All @@ -123,7 +123,7 @@ You're almost there, just check the [email configuration](docs/70_EmailConfigura
***

### User Management: Further Information
- [Custom Class Names](docs/20_CustomClassName.md)
- [Custom Class Names](docs/20_ClassCustomization.md)
- [Frontend Routes & Views](docs/30_FrontendRoutes.md)
- [Available Events](docs/40_Events.md)
- [Custom Form Types](docs/50_CustomFormTypes.md)
Expand Down
5 changes: 4 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
After every update you should check the pimcore extension manager.
Just click the "update" button or execute the migration command to finish the bundle update.

#### Update from Version 3.1.4 to Version 3.1.5
- **[ENHANCEMENT]**: You can now define a form field which is later used as object-key in Pimcore, when a user registers ([#154](https://github.com/dachcom-digital/pimcore-members/issues/154))

#### Update from Version 3.1.3 to Version 3.1.4
- **[ENHANCEMENT]**: Improving and adding additional Events for Restriction Changes on Entities ([#148](https://github.com/dachcom-digital/pimcore-members/issues/148))
- **[ENHANCEMENT]**: Update Twig navigation to allow parameters ([@kjkooistra-youwe](https://github.com/dachcom-digital/pimcore-members/pull/147))
Expand Down Expand Up @@ -44,4 +47,4 @@ Just click the "update" button or execute the migration command to finish the bu

***

Members 2.x Upgrade Notes: https://github.com/dachcom-digital/pimcore-members/blob/2.5/UPGRADE.md
Members 2.x Upgrade Notes: https://github.com/dachcom-digital/pimcore-members/blob/2.5/UPGRADE.md
16 changes: 14 additions & 2 deletions docs/20_CustomClassName.md → docs/20_ClassCustomization.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Custom Class Names
# Class Customization

### Custom names
If you want to use different class names, you need to modify the default configuration.
Add those lines to your `AppBundle/Resources/config/pimcore/config.yml`:

Expand All @@ -22,4 +23,15 @@ members:
class_name: 'identity' # default was 'SsoIdentity'
```
> **Tip:** Add this to a separate config file.
> **Tip:** Add this to a separate config file.
### Custom object keys
You can define a form field (from the registration form) whose value is used to generate the key of the Pimcore object.
```yaml
members:
user:
adapter:
object_key_form_field: 'username' # default was 'email'
```
> **Important:** Choose a unique field to prevent naming conflicts within Pimcore
4 changes: 2 additions & 2 deletions docs/SSO/20_Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ bin/console members:install:class -o
By adding the `-o` argument, this command will install the `SsoIdentity`. Already installed classes will be skipped.

If you want to use a different name, just create the class and import it from `src/MembersBundle/Resources/install/classes/class_SsoIdentity_export.json`.
Read more about changing the default class name [here](../20_CustomClassName.md).
Read more about changing the default class name [here](../20_ClassCustomization.md).

## Add SSO Identity Relation Field

Expand Down Expand Up @@ -128,4 +128,4 @@ members:
```

## Registration Types
Finally, checkout the registration type for SSO [here](../60_RegistrationTypes.md#registration-types-with-sso).
Finally, checkout the registration type for SSO [here](../60_RegistrationTypes.md#registration-types-with-sso).
1 change: 1 addition & 0 deletions src/MembersBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('class_name')->defaultValue('MembersUser')->end()
->scalarNode('object_key_form_field')->defaultValue('email')->end()
->end()
->end()
->arrayNode('initial_groups')
Expand Down
4 changes: 3 additions & 1 deletion src/MembersBundle/Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ public function updateUser(UserInterface $user, $properties = [])
//It's a new user!
if (empty($user->getKey())) {
$new = true;
$user = $this->setupNewUser($user, null);
$userConfig = $this->configuration->getConfig('user');
$key = $user->get($userConfig['adapter']['object_key_form_field']);
$user = $this->setupNewUser($user, $key);
}

// update user properties.
Expand Down

0 comments on commit 479cc26

Please sign in to comment.