def __internal_check_task_accessibility(self) -> bool: if len(self.access_list) == 0: return True current_user_name = self.config.username.upper() can_access: bool = False for access in self.access_list: account_name: str = access.account_name if current_user_name == account_name.upper(): if access.forbidden: return False if access.can_access: can_access = True target_user: User = UserFactory.get_user(account_name) if target_user.is_valid and target_user.is_group: if self.config.user.is_in_member(target_user): if access.forbidden: return False if access.can_access: can_access = True return can_access
def __internal_valid_owner(self, target_status_mnemonic: str) -> bool: if self.latest_instance is None: return True if target_status_mnemonic == self.STATUS_INIT: return True if self.__internal_check_task_accessibility else False current_status: str current_status = self.latest_instance.task_status if target_status_mnemonic == self.STATUS_APPROVAL or target_status_mnemonic == self.STATUS_REJECT: if not self._is_self_approve_enable(): requester: User = UserFactory.get_user(self.latest_instance.entry_author) if requester.is_valid and requester == self.current_user: return False for task_submit_information in self.__get_task_submission_information_list(self.latest_instance): submit_user: User = UserFactory.get_user(task_submit_information.submit_to) if submit_user.is_valid: if not submit_user.is_group and submit_user == self.current_user: return True if submit_user.is_group and self.current_user.is_in_member(submit_user): return True elif target_status_mnemonic == self.STATUS_EXECUTE: if current_status != self.STATUS_DELEGATE: if self.delegate_information.delegation_required: # self.instances current_delegated_instances = [instance for instance in self.instances if instance.task_status == self.STATUS_DELEGATE and instance.entry_author == self.current_user.userid] if len(current_delegated_instances) > 0: return True previous_user: User = UserFactory.get_user(self.latest_instance.entry_author) if previous_user.is_valid and previous_user == self.current_user: return True else: for task_submit_information in self.__get_task_submission_information_list(self.latest_instance): submit_user: User = UserFactory.get_user(task_submit_information.submit_to) if submit_user.is_valid: if not submit_user.is_group and submit_user == self.current_user: return True if submit_user.is_group and self.current_user.is_in_member(submit_user): return True elif target_status_mnemonic == self.STATUS_REQUEST: # Approver or Starter starter: User = UserFactory.get_user(self._current_task.entry_author) if starter.is_valid and starter == self.current_user: return True if self.latest_instance.task_status == self.STATUS_APPROVAL: approver: User = UserFactory.get_user(self.latest_instance.entry_author) if approver.is_valid and approver == self.current_user: return True elif target_status_mnemonic == self.STATUS_CANCEL: # Requestor requester: User = UserFactory.get_user(self.latest_instance.entry_author) if requester.is_valid and requester == self.current_user: return True elif target_status_mnemonic == self.STATUS_COMPLETE: if not self.__internal_check_task_accessibility: return False if current_status == self.STATUS_FAIL: return True else: return True return False