ppms.rights
The rights package facilitates the implementation of custom rights logic.
Classes
RightsDecorator
Base class for decorators that work with the ModuleWithRightCheck module subclass
The methods
is_user_allowed(self, user)anduser_is_not_allowed_response(self, *args, **kwargs)must be implemented in a subclass
Methods
Function | Parameters | Return Value | Description |
|---|---|---|---|
RightsDecorator.current_user_is_allowed |
| Check whether the current user has the necessary rights | |
RightsDecorator.is_user_allowed | user: Benutzer | Should return | This method must be implemented in a subclass to perform the right check for a given user |
RightsDecorator.user_is_allowed_response | args: Original arguments of the function call | Value of the original function call | Calls the function that has been decorated |
RightsDecorator.user_is_not_allowed_response | args: Original arguments of the function call | This method must be implemented in a subclass to notify the user that he/she does not have the necessary rights |
ModuleContextRightDecorator
Base class for decorators that conditionally hide actions in PLANTA
This decorator is not (!) invoked when calling the decorated function, but instead works in tandem with the
ModuleWithRightCheckto check via theis_functionality_allowedmethod if certain actions / buttons / links / context menu entries should be hidden/shown in a module
Methods
Function | Parameters | Return Value | Description |
|---|---|---|---|
is_functionality_allowed |
| Should return | This method must be implemented in a subclass to perform the right check for a given module |
ModuleWithRightCheck
Base class for modules that use a RightsDecorator to gate their methods.
The module will automatically hide buttons for which the current user does not have access rights
If the current user has the necessary rights, the buttons will be shown in the window they are customized in
Remember to call the base implementations of the methods
ModuleWithRightCheckoverrides if you further override them.When a user uses the "Save Customizing" function to save to the base MV, a ModuleWithRightCheck keeps the customized window settings regardless of whether the current user can see the button or not.
Methods
Function | Parameters | Return Value | Description |
|---|---|---|---|
ModuleWithRightCheck.control_action_display | Checks the module code for decorated functions and either unhides or hides them based on the rights of the user | ||
ModuleWithRightCheck.create_mv | title: MV name | Module variant ID | Extends the default MV creation to prevent data fields connected to a |
ModuleWithRightCheck.get_subclass_method_datafields | Fetches all data fields that have a customized module subclass method | ||
ModuleWithRightCheck.has_methods_with_right_check |
| Checks if any methods of the current class are decorated with a | |
ModuleWithRightCheck.menu_override | menu_id: Menu item id | Default menu override return values | Extends the default module variant saving menu item to prevent data fields connected to a |
ModuleWithRightCheck.on_after_mv_switch | old_mv: Previous module variant | Calls | |
ModuleWithRightCheck.on_load | Calls | ||
ModuleWithRightCheck.save_mv_by_id | id: Module variant ID |
| Extends the default implementation to prevent data fields connected to a |
Examples
Implementing a new decorator
from ppms.rights import RightsDecorator
class R41ExclusivityDecorator(RightsDecorator):
def is_user_allowed(self, user):
return user == 'R41'
def user_is_not_allowed_response(self, *args, **kwargs):
return ppms.ui_message_box('Only R41 is allowed to use this function!')
@R41ExclusivityDecorator
def some_function_exclusive_to_r41():
ppms.ui_message_box('Hello R41!')
Using the new decorator in a module subclass
from ppms.rights import ModuleWithRightCheck
class R41ExclusiveModule(ModuleWithRightCheck)
@R41ExclusivityDecorator
def exclusive_method(self):
ppms.ui_message_box('Hello R41!')
def on_load(self):
super(R41ExclusiveModule, self).on_load()
self.menu(MENU_FILTER)