Exemplo n.º 1
0
    def remove(self):
        from pyclaim.domain.aggregates.resource.model.resource import Resource
        from pyclaim.domain.aggregates.user.model.user import User

        claim_type_writer.delete(self._id)
        # todo: caution = eventual consistency rules in ddd violated we must call them by using messaging patterns - hooman
        User.claim_remove_by_claim_type(self._id)
        Resource.claim_remove_by_claim_type(self._id)
Exemplo n.º 2
0
 def execute(self):
     resource = Resource()
     resource._id = self._id
     resource_claim = Claim()
     resource_claim.claim_type_id = self.claim_type_id
     resource_claim.value = self.claim_value
     resource.claim_add(resource_claim)
     return resource_claim._id
 def validate(self, claim_id):
     from pyclaim.domain.aggregates.claim_type.model.claim_type import ClaimType
     permission_claim_type = ClaimType.get_permission()
     resource = Resource()
     resource._id = self.resource_id
     claim_is_of_claim_type = resource.claim_is_of_claim_type(claim_id, permission_claim_type._id)
     if claim_is_of_claim_type:
         super().custom.manual(ResourceErrorCodes.RESOURCE_CLAIM_WITH_PERMISSION_CLAIM_TYPE_IS_NOT_REMOVABLE)
Exemplo n.º 4
0
    def execute(self):
        from pyclaim.domain.aggregates.token.model.token import Token
        from pyclaim.domain.aggregates.user.model.user import User
        from pyclaim.domain.aggregates.resource.model.resource import Resource

        token = Token.get_by_id(self.token_id)

        if not token:
            return "Not Authenticated"

        user = User.get_by_id(token.user_id)

        if not user:
            return "Not Authenticated"

        if user.is_sys_admin():
            return "Authorized"

        resource = Resource.get_by_name(self.resource_name)

        if not resource:
            return "Not Authorized"

        for user_claim in user.claims:
            for resource_claim in resource.claims:
                if (
                    resource_claim["claim_type"]["_id"] == user_claim["claim_type"]["_id"]
                    and resource_claim["value"] == user_claim["value"]
                ):
                    return "Authorized"

        return "Not Authorized"
Exemplo n.º 5
0
 def validate(self, claim_value):
     resource = Resource()
     resource._id = self.resource_id
     exist_claim = resource.claim_exists(self.claim_type_id, claim_value)
     if exist_claim:
         super().custom.manual(ResourceErrorCodes.RESOURCE_CLAIM_EXIST)
Exemplo n.º 6
0
 def execute(self):
     resource = Resource.get_by_id(self.resource_id)
     resource_detail = ResourceDetail.create_from_resource(resource)
     return resource_detail
Exemplo n.º 7
0
 def validate(self, _id):
     is_available_id = Resource.id_exists(_id)
     if not is_available_id:
         super().custom.manual(ResourceErrorCodes.RESOURCE_ID_NOT_EXIST)
Exemplo n.º 8
0
 def validate(self, claim_id):
     resource = Resource()
     resource._id = self.resource_id
     claim_id_exist = resource.claim_id_exists(claim_id)
     if not claim_id_exist:
         super().custom.manual(ResourceErrorCodes.RESOURCE_CLAIM_ID_NOT_EXIST)
Exemplo n.º 9
0
 def validate(self, name):
     is_name_exist = Resource.name_exists(name)
     if is_name_exist:
         super().custom.manual(ResourceErrorCodes.RESOURCE_NAME_EXIST)
Exemplo n.º 10
0
 def execute(self):
     resource = Resource()
     resource._id = self._id
     resource.Name = self.name
     resource.edit()
     return "Done"
Exemplo n.º 11
0
 def execute(self):
     resource = Resource()
     resource.name = self.name
     resource.create()
     return resource._id
Exemplo n.º 12
0
 def execute(self):
     resource = Resource()
     resource._id = self._id
     resource.remove()
     return "Done"