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

Teams/Groups feature #1804

Merged
merged 1 commit into from
Aug 31, 2021
Merged

Teams/Groups feature #1804

merged 1 commit into from
Aug 31, 2021

Conversation

erikn69
Copy link
Contributor

@erikn69 erikn69 commented Aug 4, 2021

##TEAMS FEATURE

Usage in docs

A fully backwards compatible addition to for teams/groups functionality. I have added the tests and docs for this PR, and i can help to bug's review around it. I have been using this code overriding the methods with custom models for 2 years without problems, now i want to share with everyone.

Teams table must be already migrated on db, and foreign key can be customizable by config file. team_id as default. Also, i can improve the upgrade method with another migration if necessary (done, added upgrade migration and command setup-teams, roles with teams support on command create-role).

Example Communities #1782:

'teams' => true,
/*
  * Change this if you want to use teams feature and your related model
  * foreign key are other than `team_id`.
  */
'team_foreign_key' => 'community_id',

image
Where green tables(users, community_user, and communities) are handled by custom migrations. Only new pivot community_id is added to the package migration file.

Closes #1812
Closes #1782
Closes #1743
Closes #1744
Closes #1654
Closes #1629
Closes #1634
Closes #1499
Closes #1362
Closes #1353
Closes #1348
Closes #1187
Closes #1186
Closes #1135
Closes #1067
Closes #551
Closes #540
Closes #110
Closes #8
And many others

##BUGS FIX

On tests *_before_saving_object_doesnt_interfere_with_other_objects, sqls from first object are executing on second object and try to sync and load relation again(#1819)

And other small fixes that i already forget

@erikn69 erikn69 force-pushed the teams_feature branch 5 times, most recently from c14b302 to 6dd191a Compare August 5, 2021 17:14
@Restingo
Copy link

Restingo commented Aug 5, 2021

Thank you, really nice work! Can you also add a solution for a group of roles? For example one role is Documentcreator and one is Invoicecreator and you can sum them up in the role Accountant?

@systemsolutionweb
Copy link

@Restingo Why don't just assign Documentcreator and Invoicecreator?

@Restingo
Copy link

Restingo commented Aug 5, 2021

@systemsolutionweb because I've got a lot of roles that are the same for many functions / people and therefore I want to group them together for easy use.

@systemsolutionweb
Copy link

systemsolutionweb commented Aug 5, 2021

@Restingo for that you just have to add a parent table for roles, then when someone selects a group you just find for the children of that group on backend and assign them to the user, easily handled, it is not necessary to complicate the package more

Teams support is something that has been needed for a long time 👍

@erikn69
Copy link
Contributor Author

erikn69 commented Aug 6, 2021

@drbyte ready for review, now permission:show supports teams

+---------------+----------+-----------+--------------+--------------+
|               | Team ID: NULL        | Team ID: 1   | Team ID: 2   |
+---------------+----------+-----------+--------------+--------------+
|               | testRole | testRole2 | testRoleTeam | testRoleTeam |
+---------------+----------+-----------+--------------+--------------+
| Edit News     |  ·       |  ·        |  ·           |  ·           |

@erikn69 erikn69 force-pushed the teams_feature branch 2 times, most recently from c0e768d to 5fb0f55 Compare August 16, 2021 15:39
Copy link
Collaborator

@drbyte drbyte left a comment

Choose a reason for hiding this comment

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

@erikn69 Thank you for your detailed work on this PR.

I've highlighted a number of minor typographical errors,
and commented about requesting the bugfix to be split to a separate PR.

docs/basic-usage/artisan.md Outdated Show resolved Hide resolved
config/permission.php Outdated Show resolved Hide resolved
config/permission.php Outdated Show resolved Hide resolved
config/permission.php Outdated Show resolved Hide resolved
config/permission.php Outdated Show resolved Hide resolved
src/Commands/UpgradeForTeams.php Outdated Show resolved Hide resolved
src/Commands/UpgradeForTeams.php Outdated Show resolved Hide resolved
src/PermissionRegistrar.php Outdated Show resolved Hide resolved
src/PermissionRegistrar.php Outdated Show resolved Hide resolved
src/Traits/HasRoles.php Outdated Show resolved Hide resolved
@erikn69 erikn69 force-pushed the teams_feature branch 2 times, most recently from 3a4bd75 to 93c6ee9 Compare August 20, 2021 15:47
src/Models/Role.php Outdated Show resolved Hide resolved
@drbyte
Copy link
Collaborator

drbyte commented Aug 31, 2021

@erikn69 Can you review my merge-conflict resolutions?
Feel free to roll it back and re-resolve to squash the commits.

@drbyte drbyte changed the title Teams/Groups support and Bug fixes Teams/Groups feature Aug 31, 2021
@drbyte drbyte merged commit c54a494 into spatie:main Aug 31, 2021
@drbyte
Copy link
Collaborator

drbyte commented Aug 31, 2021

Thanks @erikn69 !

@jame0928
Copy link

Hola, me fuera gustado que se pudiera compartir un mismo rol para diferentes teams. Digamos que tengo un usuario que pertenece a 2 teams, y en ambos team tiene el rol de administrador. Con el modelo actual se tendrian que crear dos roles administrador, 1 para cada team, lo que hace que cada vez que se genere un nuevo team, se tenga que replicar todos los roles con sus permisos, y seria deseable que se pudieran compartir.

@erikn69
Copy link
Contributor Author

erikn69 commented Sep 27, 2021

@jame0928 si puedes usar el mismo rol en diferentes teams, lee la documentacion , los roles globales aplican los mismos permisos para todos los teams

// with null team_id it creates a global role, global roles can be used from any team and they are unique
Role::create(['name' => 'administrador', 'team_id' => null]);

Tambien puedes tener Super Admin, lee este comentario #1840 (comment)

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