Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.

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) and user_is_not_allowed_response(self, *args, **kwargs) must be implemented in a subclass

Methods

FunctionParametersReturn ValueDescription
RightsDecorator.current_user_is_allowed(self)
True or FalseCheck whether the current user has the necessary rights
RightsDecorator.is_user_allowed(self, user)user: BenutzerShould return True or FalseThis 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: Original arguments of the function call
kwargs: Original keyword arguments of the function call
Value of the original function callCalls the function that has been decorated
RightsDecorator.user_is_not_allowed_response(self, *args, **kwargs)args: Original arguments of the function call
kwargs: Original keyword 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 ModuleWithRightCheck to check via the is_functionality_allowed method if certain actions / buttons / links / context menu entries should be hidden/shown in a module

Methods

FunctionParametersReturn ValueDescription
is_functionality_allowed(self, module)
module: Current module context
Should return True or FalseThis 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 ModuleWithRightCheck overrides 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

FunctionParametersReturn ValueDescription
ModuleWithRightCheck.control_action_display(self)

Checks the module code for decorated functions and either unhides or hides them based on the rights of the user
ModuleWithRightCheck.create_mv(self, title)title: MV nameModule variant IDExtends the default MV creation to prevent data fields connected to a RightsDecorator from 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 data fields that have a customized module subclass method
ModuleWithRightCheck.has_methods_with_right_check(self)
True or FalseChecks if any methods of the current class are decorated with a RightsDecorator
ModuleWithRightCheck.menu_override(self, menu_id)menu_id: Menu item idDefault menu override return valuesExtends the default module variant saving menu item to prevent data fields connected to a RightsDecorator from 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 IDTrue or FalseExtends the default implementation to prevent data fields connected to a RightsDecorator from being moved to a different window in a MV

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!')
PY

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)
PY