rights
package makes it easier to implement custom rights logic.
ModuleWithRightCheck
module subclass is_user_allowed(self, user)
and user_is_not_allowed_response(self, *args, **kwargs)
must be implemented in a subclass
Function | Parameters | Return Value | Description |
---|---|---|---|
RightsDecorator.current_user_is_allowed(self) |
True or False |
Check if the current user has the necessary rights | |
RightsDecorator.is_user_allowed(self, user) |
user: Benutzer | Should return True or False |
This method must be implemented in a subclass to perform the right check for a given user |
RightsDecorator.user_is_allowed_response(self, *args, **kwargs) |
args: The original arguments of the function call kwargs: The original keyword arguments of the function call |
The value of the original function call | Calls the function that was decorated |
RightsDecorator.user_is_not_allowed_response(self, *args, **kwargs) |
args: The original arguments of the function call kwargs: The original keyword arguments of the function call |
This method must be implemented in a subclass to notify the user that he doesn't have the necessary rights |
ModuleWithRightCheck
to check via the is_functionality_allowed
method if certain actions / buttons / links / context menu entries should be hidden/shown in a module
Function | Parameters | Return Value | Description |
---|---|---|---|
is_functionality_allowed(self, module) |
module: The current module context |
Should return True or False |
This method must be implemented in a subclass to perform the right check for a given module |
RightsDecorator
to gate their methods. ModuleWithRightCheck
overrides if you further override them.
Function | Parameters | Return Value | Description |
---|---|---|---|
ModuleWithRightCheck.control_action_display(self) |
Checks the module code for decorated functions and either shows or hides them based on the rights of the user | ||
ModuleWithRightCheck.create_mv(self, title) |
title: MV name | Module variant ID | Extends the default MV creation to prevent datafields connected to a RightsDecorator being moved to a different window in a MV |
ModuleWithRightCheck.get_subclass_method_datafields(self) |
A dictionary of {method_name: (DA, DF, Fenster)} | Fetches all datafields that have a module subclass method customized | |
ModuleWithRightCheck.has_methods_with_right_check(self) |
True or False |
Checks if any methods of the current class are decorated with a RightsDecorator |
|
ModuleWithRightCheck.menu_override(self, menu_id) |
menu_id: Menu item id | Default menu override return values | Extends the default module variant saving menu item to prevent datafields connected to a RightsDecorator being moved to a different window in a MV |
ModuleWithRightCheck.on_after_mv_switch(self, old_mv, new_mv) |
old_mv: Previous module variant new_mv: Newly selected module variant |
Calls control_action_display |
|
ModuleWithRightCheck.on_load(self) |
Calls control_action_display |
||
ModuleWithRightCheck.save_mv_by_id(self, id) |
id: Module variant ID | True or False |
Extends the default implementation to prevent datafields connected to a RightsDecorator being moved to a different window in a MV |
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!')
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)