Example #1
0
    def approval(self, application: Application, workflow: workflow.Workflow,
                 comment: str) -> Result[Error, Application]:
        """承認する"""
        if workflow.duties not in self.duties:
            return Err(NoJobAuthorityError("職務権限がありません."))
        if application.route.is_complete():
            return Err(AlreadySottleError("決裁済みです."))
        if not application.route.has_approver(approver=self):
            return Err(NotAnApproverError("承認経路に含まれていません."))
        if application.route.has_process(approver=self):
            return Err(AlreayApproveError("承認済みです."))

        return Ok(application.process(approver=self, comment=comment))
Example #2
0
 def view(
     self, confidential: Confidential[_T]
 ) -> Result[ConfidentialPermissionError, _T]:
     """閲覧する"""
     if not confidential.visible(duties=self.duties):
         return Err(value=ConfidentialPermissionError())
     else:
         return Ok(value=confidential.get(duties=self.duties))
Example #3
0
async def authenticate(
        username: str,
        password: str) -> Result[Literal[False], account_dao.Account]:
    """認証
    """
    got_account = await account_dao.find(username=username)
    if got_account is None or not verify_password(
            plain_password=password,
            hashed_password=got_account.hashed_password):
        return Err(value=False)
    else:
        return Ok(value=got_account)
Example #4
0
        raise NotImplementedError

    async def apply(
            self, /, *,
            actor_id: entity.Id) -> Result[command.Error, workflow.Workflow]:
        """申請する"""
        raise NotImplementedError

    async def approval(
            self, /, *, actor_id: entity.Id, application_id: entity.Id,
            comment: str) -> Result[command.Error, application.Application]:
        """申請を承認する"""

        actor, approve_application, approve_workflow = await self.repository.get(
            employee_id=actor_id, application_id=application_id)

        if actor is None or approve_application is None or approve_workflow is None:
            raise FileNotFoundError

        result = actor.as_role(role=application.ApproverRole).approval(
            application=approve_application,
            workflow=approve_workflow,
            comment=comment)

        if isinstance(result, Err):
            return Err(value=command.Error(result.value))
        else:
            _, _, _ = await self.repository.save(
                application_entity=result.value)
            return Ok(value=result.value)
Example #5
0
 def result(x: bool) -> Result[Literal["Err"], Literal["Ok"]]:
     return Ok("Ok") if x else Err("Err")
Example #6
0
    async def get(
        employee_id: entity.Id, application_id: entity.Id
    ) -> Result[
        Exception,
        Tuple[
            Optional[employee.Employee],
            Optional[application.Application],
            Optional[workflow.Workflow],
        ],
    ]:
        try:
            got_employee_dto = await employee_dao.get(id_=employee_id)
            got_employee = (
                None
                if got_employee_dto is None
                else employee.Employee(
                    id_=mongodb.ULID(got_employee_dto.id_),
                    username=got_employee_dto.username,
                    full_name=got_employee_dto.full_name,
                    email_address=got_employee_dto.email_address,
                    hashed_password=got_employee_dto.hashed_password,
                    duties=Vector(
                        [governance.Duties(item) for item in got_employee_dto.duties]
                    ),
                    join_date=got_employee_dto.join_date,
                    retirement_date=got_employee_dto.retirement_date,
                    disabled=got_employee_dto.disabled,
                )
            )

            got_application_dto = await application_dao.get(id_=application_id)
            got_application = (
                None
                if got_application_dto is None
                else application.Application(
                    id_=mongodb.ULID(got_application_dto.id_),
                    applicant_id=mongodb.ULID(got_application_dto.applicant_id),
                    workflow_id=mongodb.ULID(got_application_dto.workflow_id),
                    route=application.Route(
                        [
                            application.Progress(
                                approver_id=mongodb.ULID(progress.approver_id),
                                approve=progress.approve,
                                process_datetime=progress.process_datetime,
                                comment=progress.comment,
                            )
                            for progress in got_application_dto.route
                        ]
                    ),
                )
            )

            got_workflow_dto = await workflow_dao.get(id_=got_application.workflow_id)
            got_workflow = (
                None
                if got_workflow_dto is None
                else workflow.Workflow(
                    id_=mongodb.ULID(got_workflow_dto.id_),
                    name=got_workflow_dto.name,
                    description=got_workflow_dto.description,
                    duties=governance.Duties(got_workflow_dto.duties),
                )
            )

        except Exception as error:
            return Err(error)
        return Ok((got_employee, got_application, got_workflow))
Example #7
0
class ManagerRole(employee.Employee):
    """部門管理者ロール"""

    def create(
        self,
        /,
        *,
        id_: entity.Id,
        name: str,
        description: str,
        duties: governance.Duties,
    ):
        """ワークフローを新規作成する"""

        if not name:
            return Err(NoNameError("名称が未定です."))
        if not description:
            return Err(NoDescriptionError("説明が未記入です."))
        if duties not in self.duties:
            return Err(NoJobAuthorityError("職務権限がありません."))

        return Ok(Workflow(id_=id_, name=name, description=description, duties=duties))

    def edit(
        self,
        /,
        *,
        workflow: Workflow,
        name: str,
        description: str,
        duties: governance.Duties,