Download the PHP package democracyapps/member-org without Composer
On this page you can find all versions of the php package democracyapps/member-org. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download democracyapps/member-org
More information about democracyapps/member-org
Files in democracyapps/member-org
Package member-org
Short Description Application support for multiple organization types, each with its own users and permissions
License MIT
Informations about the package member-org
member-org
Laravel application support for multiple org types, each with own users with multiple permission levels. Organization and OrganizationMember present an interface, while EloquentMemberOrganization and EloquentOrganizationMember are traits that provide a full implementation when added to an Eloquent model.
The package is quite simple. It's most useful when a platform must support multiple types of organizations and organization members at the same time.
Important: If you are thinking of using this package, please contact me via Twitter (@ejaxon). I am considering adding functionality around user invites, user management, migrations, etc.
Instructions For Use
Installation
Begin by installing this package through Composer.
Add the service provider to app.php
(note that the service provider is currently only needed if you wish to publish the configuration file in order to change the defaults.
The only requirement right now is that the user class obey Laravel's Authenticable contract.
Note that the EloquentOrganizationMember train only has stubs for the OrganizationMember interface (unlike EloquentMemberOrganization). I am holding off until I better understand requirements for it (if any).
Applying to an Organization
Let's assume that you have a Company class to which you wish to apply this package and that Company is a subclass of Eloquent Model:
Change the class to implement the Organization interface and make use of the EloquentOrganization trait:
In addition, create a CompanyMember class (NOTE: the 'Member' part of the name is required. An option in the configuration file will allow it to be set to something different.):
and create a migration for it. It is required to have three columns:
None of the columns may be null. Note that the second column must be named with the snake_case version of your organization class with '_id" appended.
Configuration Parameters
There are three main parameters and a few auxiliary ones. If you wish to change the defaults, add the service provider, run
php artisan vendor:publish
and edit 'config/member-org.php'.
max_permission_level (default: 9)
Permissions are simple - each organization member is assigned an access level between 0 and max_permission_level. Pages and resources in your application can be assigned required access levels and users with access below the required level will fail the userHasAccess test.
I typically begin by assigning only two levels, 0 for no privileges and 9 for administrators, leaving intermediate values available for later use.
user_implements_superuser (default: false)
If set to true, the package expects the user table to contain a boolean column which, if true, makes the user a "superuser" who always has access to any resource or page. By default, the column name is assumed to be 'superuser', but this can be changed in the configuration file.
user_implements_confirmation (default: false)
If set to true, the package expects that the application requires users to verify their accounts in some way and that they should not gain full privileges until they do. Their status should be indicated in a boolean column in the user table (by default the column name is assumed to be 'confirmed', but this can be changed in the configuration file).
The user_confirmation_required_threshold (default:0) specifies the maximum privilege level they may have before verifying their accounts. Thus, a full administrator (access=9) would remain restricted to access level 0 by default until verification is completed.
Basic Use
So far I am making use of the package in two simple ways. First, I use the Organization's addMember method to create organization users (this creates the entry in the database). Second, I use the Organization's userHasAccess method in route middleware to restrict access to organization pages (generally admin pages).
Here is a concrete example of a middleware class for company admin pages. In the route, the company ID is in the 2nd route segment.
Problems and Plans
This module is being used for a couple products in active development and will probably evolve. If you find bugs or have requests for features, create an issue here, find me on Twitter (@ejaxon) or submit a pull request.