pwix:accounts-manager
What is it ?
A try to mutualize and factorize the most common part of a simple accounts management system:
-
defines the account schema and provides client and server check functions
-
provides components to list and edit accounts.
Most of the configuration is done through the provided class which must be insciated in common application code.
Provides
AccountsManager
The exported AccountsManager global object provides following items:
Classes
AccountsManager.amClass
The AccountsManager.amClass class notably determines which schema is handled in which collection. All permissions are also managed at this class level.
This class must be instanciated by the application in its common code.
Constructor takes an object as single argument, with following keys:
-
baseFieldsetWhen set, the
baseFieldsetis expected to provide aField.Setdefinition for schema, tabular and forms handlings.It defaults to a standard (though a bit extended) schema from Meteor
accounts-baseas:
1 { 2 _id: { 3 type: String 4 }, 5 emails: { 6 type: Array, 7 optional: true 8 }, 9 'emails.$': { 10 type: Object 11 }, 12 'emails.$.address': { 13 type: String, 14 regEx: SimpleSchema.RegEx.Email, 15 }, 16 'emails.$.id': { 17 type: String 18 }, 19 'emails.$.verified': { 20 type: Boolean 21 }, 22 username: { 23 type: String, 24 optional: true 25 }, 26 profile: { 27 type: Object, 28 optional: true, 29 blackbox: true 30 }, 31 services: { 32 type: Object, 33 optional: true, 34 blackbox: true 35 }, 36 lastConnection: { 37 type: Date 38 }, 39 loginAllowed: { 40 type: Boolean, 41 defaultValue: true 42 }, 43 userNotes: { 44 type: String 45 }, 46 adminNotes: { 47 type: String 48 } 49 }
Providing a `baseFieldset` replaces the above default fieldset definition
-
additionalFieldsetWhen set, let the application extends the above default fieldset by providing additional fields as a
Field.Setdefinition.Defauts to nothing.
Example:
1 additionalFieldset: [ 2 { 3 before: 'createdAt', 4 fields: [ 5 { 6 name: 'apiAllowed', 7 type: Boolean, 8 defaultValue: false 9 } 10 ] 11 } 12 ]
-
allowFnAn async function which will be called with an action string identifier, and must return whether the current user is allowed to do the specified action.
If the function is not provided, then the default is to deny all actions (and do you really want that ?).
allowFnprototype is:async allowFn( action<String> [, ...<Any> ] ): Boolean -
classesLet the application provides some classes to add to the display. The classes mentionned here are added to the configured values if any.
Defauts to nothing.
-
collectionWhen set, the name of the collection to be managed.
Defauts to the standard Meteor
userscollection.Each managed collection is made timestampable, and following fields are added (and maintained) to the fieldset definition:
1 createdAt 2 updatedAt 3 CreatedBy 4 updatedBy
-
hideDisabledWhether to hide disabled actions instead of displaying the disabled state.
Defaults to
true: disabled actions are hidden. -
haveRolesWhether to display a Roles panel, defaulting to
true.For the Roles panel be actually displayed, this
haveRolesargument must betrue, AND thepwix:rolespackage must be used by the application (it is not used by this package). -
withGlobalsWhether the Roles panel, when displayed, should include a "Global roles" pane, defaulting to
true. -
withScopedWhether the Roles panel, when displayed, should include a "Scoped roles" pane, defaulting to
true. -
scopesFnAn application-provided async function which is expected to return all existing (roles) scopes.
Defaults to only manage scopes that are already used in the
Rolespackage. -
tabularActiveCheckboxesWhether the checkboxes rendered in the tabular display are active, i.e. accept a click to switch their state.
Rationale: even if it would be very more easy to directly click on the tabular display to toggle a checkbox, some administrators may find this way too much easy, if not error prone, and prefer to have to pass through a distinct page/modal/display unit to securize a bit this update.
Defaults to
false.
Functions
AccountsManager.configure( o<Object> )
See below
AccountsManager.i18n.namespace()
Returns the i18n namespace used by the package. Used to add translations at runtime.
Available both on the client and the server.
Blaze components
AccountEditPanel
A tabbed editing panel to be run inside of a page or of a modal. Default tabs are named and ordered as:
ident_tabadmin_notes_tabuser_notes_tab
If the pwix:roles package is used by the application, a roles_tab is inserted before admin_notes_tab.
When run from AccountsList, it is run in a modal to edit the current item.
AccountNewButton
A PlusButton component customized to create a new account.
It takes itself care of checking the permissions of the user, and, depending of its runtime parameters, either is disabled, or doesn't display at all if the user is not allowed.
It takes the very same data context than below AccountsList.
AccountsList
The component list the defined accounts as a pwix:tabular table, with standard 'Informations', 'Edit' and 'Delete' buttons.
It takes itself care of checking the permissions of the user, and, depending of its runtime parameters, either disabled, or doesn't display at all, the relevant buttons if the user is not allowed.
Known data context is:
-
nameThe collection name to list, defaulting to standard Meteor
users -
tabsAn optional array of tabs to be displayed before the 'roles' tab (if any).
Permissions management
This package can take advantage of pwix:permissions package to manage the user permissions.
It defines following tasks:
-
at the user interface level
pwix.accounts_manager.feat.edit, with argsuser<String|Object>: edit theuseraccountpwix.accounts_manager.feat.new: display a button to create a new account
-
at the server level
pwix.accounts_manager.fn.removeAccount, with argsuser<String|Object>, amInstance<amClass>: remove theuseraccountpwix.accounts_manager.fn.updateAccount, with argsuser<Object>, amInstance<amClass>: update theuseraccountpwix.accounts_manager.fn.updateAttribute, with argsuser<String|Object>, amInstance<amClass>, modifier<Object>: apply themodifierMongo modifier to theuseraccount
-
on publications
pwix.accounts_manager.pub.list_all, with argsuser<String|Object>, amInstance<amClass>: list all accounts and their contents (but theserviceandprofileobjects)
Configuration
This package relies on pwix:accounts-conf package for most of its configuration. Please see the relevant documentation.
This package's behavior can be configured through a call to the AccountsManager.configure() method, with just a single javascript object argument, which itself should only contains the options you want override.
Known configuration options are:
-
classesLet the application provides some classes to add to the display.
Defauts to nothing.
-
datetimeThe
strftimeformat string used to display date and time timestamps.Defaults to
%Y-%m-%d %H:%M:%S. -
verbosityThe verbosity level as:
AccountsManager.C.Verbose.NONE
or an OR-ed value of integer constants:
-
AccountsManager.C.Verbose.CONFIGURETrace configuration operations
-
AccountsManager.C.Verbose.FUNCTIONSTrace functions calls
-
AccountsManager.C.Verbose.INSTANCETrace
amClassinstanciation
Defaults to
AccountsManager.C.Verbose.CONFIGURE.
A function can be provided by the application for each of these parameters. The function will be called without argument and must return a suitable value.
Please note that AccountsManager.configure() method should be called in the same terms both in client and server sides.
Remind too that Meteor packages are instanciated at application level. They are so only configurable once, or, in other words, only one instance has to be or can be configured. Addtionnal calls to AccountsManager.configure() will just override the previous one. You have been warned: only the application should configure a package.
AccountsManager.configure() is a reactive data source.
NPM peer dependencies
Starting with v 1.0.0, and in accordance with advices from the Meteor Guide, we no more hardcode NPM dependencies in the Npm.depends clause of the package.js.
Instead we check npm versions of installed packages at runtime, on server startup, in development environment.
Dependencies as of v 1.1.0:
1 'email-validator': '^2.0.4', 2 'lodash': '^4.17.0', 3 'strftime': '^0.10.2'
Each of these dependencies should be installed at application level:
meteor npm install <package> --save
Translations
New and updated translations are willingly accepted, and more than welcome. Just be kind enough to submit a PR on the Github repository.
Cookies and comparable technologies
None at the moment.
Issues & help
In case of support or error, please report your issue request to our Issues tracker.
P. Wieser
- Last updated on 2024, Aug. 11th