rights

The rights package makes it easier to implement 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

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

The base class for modules that use a RightsDecorator to gate their methods.

  • The module will automatically hide buttons that the current user doesn't have the rights to access
  • 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.

Methods

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

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)

web-bg-small 39.5 Venus Current DE

         PLANTA project









 
  • Suche in Topic-Namen

  • Suche in Topic-Inhalten