pwix:accounts-manager

v1.0.0Published 3 months ago

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.

Schema

pwix:accounts-manager is based on Meteor accounts-base, and extends its standard schema as:

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    }

As it also makes the collection timestampable, following fields are added and maintained too:

1    createdAt
2    updatedAt
3    CreatedBy
4    updatedBy

Provides

AccountsManager

The exported AccountsManager global object provides following items:

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_tab
  • roles_tab
  • admin_notes_tab
  • user_notes_tab

When run from (below) AccountsList, it is run in a modal to edit the current item.

The AccountEditPanel component accepts a data context as:

  • item: the item to be edited, or null (or unset)

  • tabbed: the item to be edited, or null (or unset)

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.

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:

  • classes: the classes to be added to any display, defaulting to none

  • disableUnallowed: whether to display the unallowed functions as disabled buttons, defaulting to true.

    When false, the unallowed functions links are not displayed at all.

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 args user<String|Object>: edit the user account
    • pwix.accounts_manager.feat.new: display a button to create a new account
  • at the server level

    • pwix.accounts_manager.fn.removeAccount, with args user<String|Object>: remove the user account
    • pwix.accounts_manager.fn.updateAccount, with args user<Object>: update the user account
    • pwix.accounts_manager.fn.updateAttribute, with args user<String|Object>, modifier<Object>: apply the modifier Mongo modifier to the user account
  • on publications

    • pwix.accounts_manager.pub.list_all: list all accounts and their contents (but the service and profile objects)

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:

  • allowFn

    An 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.

    allowFn prototype is: async allowFn( action<String> [, ...<Any> ] ): Boolean

  • classes

    Let the application provides some classes to add to the display.

    Defauts to nothing.

  • datetime

    The strftime format string used to display date and time timestamps.

    Defaults to %Y-%m-%d %H:%M:%S.

  • fields

    Let the application extends the default schema by providing additional fields as a Forms.FieldSet definition.

    Defauts to nothing.

    Example:

1    AccountsManager.configure({
2        fields: [
3            {
4                where: Field.C.Insert.BEFORE,
5                name: 'loginAllowed',
6                fields: [
7                    {
8                        name: 'apiAllowed',
9                        type: Boolean,
10                        defaultValue: false
11                    }
12                ]
13            }
14        ]
15    });
  • hideDisabled

    Whether to hide disabled actions instead of displaying the disabled state.

    Defaults to true: disabled actions are hidden.

  • scopesFn

    An application-provided function which is expected to return all existing (roles) scopes.

    Defaults to only manage scopes that are already used in the Roles package.

  • tabularActiveCheckboxes

    Whether 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.

  • verbosity

    The verbosity level as:

    • AccountsManager.C.Verbose.NONE

    or an OR-ed value of integer constants:

    • AccountsManager.C.Verbose.CONFIGURE

      Trace configuration operations

    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.0.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, Jul. 18th