Caplin Trader 5.1.0

Class: module:ct-services/testing/PermissionServiceStub

module:ct-services/testing/PermissionServiceStub()

The PermissionServiceStub serves to provide a way for tests to stub a ct-services/security/PermissionService providing trading and view allow or deny permissions on tiles and instruments.

Register a module:ct-trading/testing/PermissioningServiceStub service on the module:ct-core/ServiceRegistry under the namespace "ct-services/security/PermissionService".

Constructor

new module:ct-services/testing/PermissionServiceStub()

Constructs a PermissionServiceStub.

Implements:

Methods

addAttributeListener(attributeName, listener)

Registers a listener that subscribes to current and future values of a single user attribute. After calling this method, the registered listener will be notified of the value of the user attribute.

This is the value assigned to the logged in user. To be notified of the value assigned to the user they are trading on behalf of, call module:ct-security/permissioning/PermissionService#addToboUserAttributeListener instead.

The listener that you register must implement module:ct-services/security/PermissionServiceListener#onAttributeChanged, which is called when the listener is first registered and also when the value of the attribute changes.

Parameters:
Name Type Description
attributeName string

The name of the user attribute that you want to subscribe to.

listener module:ct-services/security/PermissionServiceListener

The listener object that will receive the subscription updates.

Implements:

addGlobalPermissionListener(product, action, listener) → {int}

Registers a listener that subscribes to current and future permissions for an action on a single product in the global (default) namespace. After calling this method, the registered listener will be notified of the permission that the user has for the requested action on the specified product.

The listener that you register must implement module:ct-services/security/PermissionServiceListener#onSinglePermissionChanged, which is called when the listener is first registered and also when the product permission changes.

Note: If you want to specify a different namespace, then use module:ct-security/permissioning/PermissionService#addPermissionListener instead.

Parameters:
Name Type Description
product string

The name of the product that the subscription is for (for example '/FX/EURUSD').

action string

The action that the subscription is for (for example 'TRADE').

listener module:ct-services/security/PermissionServiceListener

The listener object that will receive the subscription updates.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#canUserPerformGlobalAction
  • module:ct-security/permissioning/PermissionService#removeListener
Returns:

A unique indentifier that allows the listener to be removed from the listener register (see module:ct-security/permissioning/PermissionService#removeListener).

Type
int

addPermissionListener(product, namespace, action, listener) → {int}

Registers a listener that subscribes to current and future permissions for an action on a single product in a given namespace. After calling this method, the registered listener will be notified of the permission that the user has for the requested action on the specified product.

The listener that you register must implement module:ct-services/security/PermissionServiceListener#onSinglePermissionChanged, which is called when the listener is first registered and also when the product permission changes.

Note: If you want to specify the global (default) namespace, then use module:ct-security/permissioning/PermissionService#addGlobalPermissionListener instead.

Parameters:
Name Type Description
product string

The name of the product that the subscription is for (for example '/FX/EURUSD').

namespace string

The namespace in which the product permission resides (for example 'tenors').

action string

The action that the subscription is for (for example 'TRADE').

listener module:ct-services/security/PermissionServiceListener

The listener object that will receive the subscription updates.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#canUserPerformAction
  • module:ct-security/permissioning/PermissionService#removeListener
Returns:

A unique identifier that allows the listener to be removed from the listener register (see module:ct-security/permissioning/PermissionService#removeListener).

Type
int

addPermissionSetListener(product, namespaceopt, type, listener) → {int}

Registers a listener that subscribes to a set of current and future permissions on a single product in a given namespace. You can subscribe to module:ct-security/permissioning/PermissionService#ALL permissions, module:ct-security/permissioning/PermissionService#ALLOW permissions, or module:ct-security/permissioning/PermissionService#DENY permissions.

After calling this method, the registered listener will be notified of the set of actions in the given namespace for which the user has the requested permission. A typical use would be to subscribe to the set of permitted tenors on a product.

The listener that you register must implement module:ct-services/security/PermissionServiceListener#onPermissionsChanged, which is called when the listener is first registered and also when a product permission changes.

Parameters:
Name Type Attributes Description
product string

The name of the product that the subscription is for (for example '/FX/EURUSD').

namespace string <optional>

The namespace in which the product permission resides (for example 'tenors'). If null, then the permission resides in the global (default) namespace.

type string

The type of permission that the subscription is for (module:ct-security/permissioning/PermissionService#ALL, module:ct-security/permissioning/PermissionService#ALLOW, or module:ct-security/permissioning/PermissionService#DENY).

listener module:ct-services/security/PermissionServiceListener

The listener object that will receive the subscription updates.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#getAllowPermissions
  • module:ct-security/permissioning/PermissionService#getAllPermissions
  • module:ct-security/permissioning/PermissionService#getDenyPermissions
  • module:ct-security/permissioning/PermissionService#removeListener
Returns:

A unique identifier that allows the listener to be removed from the listener register (see module:ct-security/permissioning/PermissionService#removeListener).

Type
int

addProductPermissionsListener(products, namespaceopt, action, isAuthorized, listener) → {int}

Registers a listener that subscribes to current and future permissions on a set of products. You can subscribe to products for which an action is either alllowed or denied.

After calling this method, the registered listener will be notified of the subset of products for which the user has the requested permission for the requested action.

The listener that you register must implement module:ct-services/security/PermissionServiceListener#onPermissionsChanged, which is called when the listener is first registered and also when a permission changes for any product in the given set of products.

Parameters:
Name Type Attributes Description
products Array.<string>

An array of strings representing the set of products that the subscription is for.

namespace string <optional>

The namespace in which the product permission resides (for example 'tenors'). If null, then the permission resides in the global (default) namespace.

action string

The action that the subscription is for (for example 'TRADE').

isAuthorized boolean

The type of permission that the subscription is for (true for allowed permissions and false for denied permissions).

listener module:ct-services/security/PermissionServiceListener

The listener object that will receive the subscription updates.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#getPermissionedProducts
  • module:ct-security/permissioning/PermissionService#getUnpermissionedProducts
  • module:ct-security/permissioning/PermissionService#removeListener
Returns:

A unique identifier that allows the listener to be removed from the listener register (see module:ct-security/permissioning/PermissionService#removeListener).

Type
int

addRegistrationListener(callback)

Allows the user to register a callback method that will be caled every time addPermissionListener() is called this enable a workbench tool to update its GUI.

Parameters:
Name Type Description
callback function

Method to be called any time addPermissionListener is called

allow()

Notifies the appropiate listeners that a permission defined by namespace, product and action is allowed

canUserPerformAction(product, namespace, action) → {boolean}

Determines whether an action on a product is allowed or denied in a given permissioning namespace.

Note: If you want to specify the global (default) namespace, then use module:ct-security/permissioning/PermissionService#canUserPerformGlobalAction instead.

Parameters:
Name Type Description
product string

The name of the product (for example '/FX/EURUSD').

namespace string

The namespace in which the product permission resides (for example 'tenors').

action string

The action on which the permission may be granted (for example 'TRADE').

Implements:
Returns:

true if the action is allowed, false if the action is denied.

Type
boolean

canUserPerformGlobalAction(product, action) → {boolean}

Determines whether an action on a product is allowed or denied in the global (default) namespace.

Note: If you want to specify a different namespace, then use module:ct-security/permissioning/PermissionService#canUserPerformAction instead.

Parameters:
Name Type Description
product string

The name of the product (for example '/FX/EURUSD').

action string

The action on which the permission may be granted (for example 'TRADE').

Implements:
Returns:

true if the action is allowed, false if the action is denied.

Type
boolean

deny()

Notifies the appropiate listeners that a permission defined by namespace, product and action is denied

dispose()

Disposes of any listeners and resources that were used by the service.

Implements:

getAllowPermissions(product, namespaceopt, sortFunctionopt) → {Array.<string>}

Returns the set of actions that are allowed on a product within a given namespace. A typical use would be to retrieve the set of allowed tenors on a product.

Parameters:
Name Type Attributes Description
product string

The name of the product (for example '/FX/EURUSD').

namespace string <optional>

The namespace in which the product permissions reside (for example 'tenors'). If null, then the permissions reside in the global (default) namespace.

sortFunction function <optional>

An optional function used to sort the list of permissions returned from the PermissionEngine, if not passed in, the permissions will be returned unsorted.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#getAllPermissions
  • module:ct-security/permissioning/PermissionService#getDenyPermissions
  • module:ct-security/permissioning/PermissionService#addPermissionSetListener
Returns:

An array of strings representing actions that are allowed on the product.

Type
Array.<string>

getAllPermissions(product, namespaceopt) → {Array.<string>}

Returns the entire set of permissioned actions on a product within a given namespace. The entire set includes the actions that are allowed and the actions that are denied.

Parameters:
Name Type Attributes Description
product string

The name of the product (for example '/FX/EURUSD').

namespace string <optional>

The namespace in which the product permissions reside (for example 'tenors'). If null, then the permissions reside in the global (default) namespace.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#getAllowPermissions
  • module:ct-security/permissioning/PermissionService#getDenyPermissions
  • module:ct-security/permissioning/PermissionService#addPermissionSetListener
Returns:

An array of strings representing all permissioned actions on the product (allowed and denied).

Type
Array.<string>

getDenyPermissions(product, namespaceopt) → {Array.<string>}

Returns the set of actions that are denied on a product within a given namespace. A typical use would be to retrieve the set of denied tenors on a product.

Parameters:
Name Type Attributes Description
product string

The name of the product (for example '/FX/EURUSD').

namespace string <optional>

The namespace in which the product permissions reside (for example 'tenors'). If null, then the permissions reside in the global (default) namespace.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#getAllPermissions
  • module:ct-security/permissioning/PermissionService#getAllowPermissions
  • module:ct-security/permissioning/PermissionService#addPermissionSetListener
Returns:

An array of strings representing actions that are denied on the product.

Type
Array.<string>

getUserAllowedProducts(namespaceopt, action) → {Array.<string>}

Returns the products that have 'Allow' permission for a given namespace and action.

The allowed products are always for the logged in user only, even if they are trading on behalf of another user. To get allowed products for the user they are trading on behalf of, call module:ct-security/permissioning/PermissionService#getToboAllowedProducts instead.

A typical use would be to get the users (as an array of products) that the logged in user can trade on behalf of (TOBO). By convention, the namespace of such products is 'TradeOnBehalfOf' and the action is 'ChangeTradeOnBehalfOfUser'. For further information about TOBO, refer to the document Caplin Platform: Permissioning Overview And Concepts.

Parameters:
Name Type Attributes Description
namespace string <optional>

The namespace in which the product permissions reside (for example 'tenors' or 'TradeOnBehalfOf'). If omitted or set to null, the product permissions reside in the global (default) namespace.

action string

The action that is allowed (for example '1-Week' or 'ChangeTradeOnBehalfOfUser').

Implements:
Returns:

An array of strings representing the allowed products. Each string in the array could be a JavaScript regular expression that matches more than one product.

Type
Array.<string>

getUserAttribute(attributeName) → {string}

Gets the current value of a user attribute.

This is the value assigned to the logged in user. To get the value assigned to a user they are trading on behalf of, call module:ct-security/permissioning/PermissionService#getToboUserAttribute instead.

Parameters:
Name Type Description
attributeName string

The name of the user attribute that you want the value of.

Implements:
Returns:

The value of the user attribute.

Type
string

getUserDeniedProducts(namespaceopt, action) → {Array.<string>}

Returns the products that have 'Deny' permission for a given namespace and action.

The denied products are always for the logged in user only, even if they are trading on behalf of another user. To get denied products for the user they are trading on behalf of, call module:ct-security/permissioning/PermissionService#getToboDeniedProducts instead.

Parameters:
Name Type Attributes Description
namespace string <optional>

The namespace in which the product permissions reside (for example 'tenors'). If omitted or set to null, the product permissions reside in the global (default) namespace.

action string

The action that is denied (for example '1-week').

Implements:
Returns:

An array of strings representing the denied products. Each string in the array could be a JavaScript regular expression that matches more than one product.

Type
Array.<string>

removeListener(listenerId)

Removes a listener from the listener register. The removed listener will no longer be notified of current or future product permissions.

Parameters:
Name Type Description
listenerId int

The unique identifier that was returned when the listener was registered.

Implements:
See:
  • module:ct-security/permissioning/PermissionService#addPermissionListener
  • module:ct-security/permissioning/PermissionService#addGlobalPermissionListener
  • module:ct-security/permissioning/PermissionService#addProductPermissionsListener
  • module:ct-security/permissioning/PermissionService#addPermissionSetListener

setAllPermissionsForProductSets(m_permissionedProducts)

This method allows you to override the existing list of product sets. Product set listeners will be notified about product sets changes.

Parameters:
Name Type Description
m_permissionedProducts Object

Product set map. Each key will represent a namespace and its value will be an array of products.

setProductSetsPermissions(namespace, products)

Allows to set product sets permissions. It will callback on the product sets listeners registered for the given namespace.

Parameters:
Name Type Description
namespace String

Namespace identifying the product set.

products Array

Array of products for the given namespace.