class CreatePermissionInput(graphene.InputObjectType): """Input Object for CreatePermission Args: name (str): Name of the new permission subject_id (str): UUID of subject to whom the permission is granted subject_type (PermissionSubjectType): Type of the subject user, group or role comment (Optional[str]): Comment for the permission resource_id (Optional[str]): UUID of entity to which the permission applies resource_type (Optional[EntityType]): Type of the resource. For Super permissions user, group or role """ name = graphene.String(required=True, description="Name of the new permission.") subject_id = graphene.UUID( required=True, description="UUID of subject to whom the permission is granted.", ) subject_type = PermissionSubjectType( required=True, description="Type of the subject user, group or role.") comment = graphene.String(description="Comment for the permission.") resource_id = graphene.UUID( description="UUID of entity to which the permission applies.") resource_type = PermissionEntityType( description="Type of the resource. For Super permissions user," " group or role.")
class ModifyPermissionInput(graphene.InputObjectType): """Input object for modifyPermission. Args: id (UUID): UUID of permission to be modified. comment (str, optional): The comment on the permission. name (str, optional): Permission name, currently the name of a command. subject_id (str, optional): UUID of subject to whom the permission is granted. subject_type (PermissionSubjectType, optional): Type of the subject user, group or role. resource_id (str, optional): UUID of entity to which the permission applies. resource_type (PermissionEntityType, optional): Type of the resource. For Super permissions user, group or role. """ permission_id = graphene.UUID(required=True, description="ID of permission to modify.", name='id') comment = graphene.String(description="Permission comment.") name = graphene.String(description="Permission name.") subject_id = graphene.UUID( description="Id of subject whom the permission is granted.") subject_type = PermissionSubjectType( description="Type of the subject user, group or role.") resource_id = graphene.UUID( description="UUID of entity to which the permission applies.") resource_type = PermissionEntityType( description="Type of the resource. For Super permissions " "user, group or role.")
def mutate(root, info, input_object): permission_id = (str(input_object.permission_id) if input_object.permission_id is not None else None) comment = (input_object.comment if input_object.comment is not None else None) name = input_object.name if input_object.name is not None else None subject_id = (str(input_object.subject_id) if input_object.subject_id is not None else None) subject_type = (PermissionSubjectType.get(input_object.subject_type) if input_object.subject_type is not None else None) resource_id = (str(input_object.resource_id) if input_object.resource_id is not None else None) resource_type = (PermissionEntityType.get(input_object.resource_type) if input_object.resource_type is not None else None) gmp = get_gmp(info) gmp.modify_permission( permission_id, comment=comment, name=name, resource_id=resource_id, resource_type=resource_type, subject_id=subject_id, subject_type=subject_type, ) return ModifyPermission(ok=True)
def mutate(root, info, input_object): gmp = get_gmp(info) # Required args name = input_object.name if input_object.name is not None else None subject_id = (str(input_object.subject_id) if input_object.subject_id is not None else None) subject_type = (PermissionSubjectType.get(input_object.subject_type) if input_object.subject_type is not None else None) # Optional args resource_id = (str(input_object.resource_id) if input_object.resource_id is not None else None) resource_type = (PermissionEntityType.get(input_object.resource_type) if input_object.resource_type is not None else None) comment = (input_object.comment if input_object.comment is not None else None) elem = gmp.create_permission( name=name, subject_id=subject_id, subject_type=subject_type, resource_id=resource_id, resource_type=resource_type, comment=comment, ) return CreatePermission(id_of_created_permission=elem.get('id'))