def mutate(root, info, where=None, _set=None): with transaction.atomic(): # call different functions depending on what is changed # TODO allow changing multiple columns at the same time auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) if not _set.parent is None: data = { 'role_id': where.id._eq, 'parent_id': _set.parent, 'view': ReconciliationView, } data = change_role_parent(data, auth) elif not _set.asset_id is None: # assigns an asset to the role, # if moving asset to unassigned assets, the role_id is 0 / None data = { 'role_id': where.id._eq, 'asset_id': _set.asset_id, 'view': ReconciliationView, } if where.id._eq == 3: data = remove_reconciliation_asset(data, auth) else: data = assign_asset_to_role_reconciliation(data, auth) else: raise GraphQLError('Unimplemented') if data.success: data = ReconciliationView.objects.filter(pk=data.obj_id) return UpdateReconciliationView(returning=data) raise GraphQLError(data.readable_message())
def mutate(root, info, objects=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) data = objects.__dict__ data.update({ 'role_spatial_site_id': 1, # objects.role_spatial_site_id 'role_priority': 'a', # objects.role_priority 'role_criticality': 'a', # objects.role_criticality 'parent_id': objects.parent, 'view': ReconciliationView, }) if data.get('id'): # add asset only change_type = 3 elif data.get('asset_serial_number'): # add role + asset change_type = 1 else: # add role only change_type = 2 new_entity = add_missing_role_asset(data, change_type, auth) if new_entity.success: new_entity = ReconciliationView.objects.filter( pk=new_entity.obj_id) return InsertReconciliationView(returning=new_entity) raise GraphQLError(new_entity.readable_message())
def mutate(root, info, where=None, _set=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) if not where.id is None: # delete role data = { 'role_id': where.id._eq, 'entity_exists': False, 'view': ReconciliationView, } result = ReconciliationView.objects.filter(pk=where.id._eq) data = remove_reconciliation(data, auth) elif not where.asset_id is None: # delete asset data = { 'asset_id': where.asset_id._eq, 'entity_exists': False, 'view': ReconciliationView, } result = ReconciliationView.objects.filter( asset_id=where.asset_id._eq) data = remove_reconciliation_asset(data, auth) if data.success: return DeleteReconciliationView(returning=result) raise GraphQLError(data.readable_message())
def mutate(root, info, objects=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) data = {'asset_serial_number': objects.asset_serial_number} data = MissingAssetUtil(data, auth) if data['result'] == 0: data = list( UnassignedAssetsView.objects.filter(pk=data['errors'])) return InsertReconciliationUnassignedAssetView(returning=data) raise GraphQLError(data['errors'])
def mutate(root, info, objects=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) data = {'asset_serial_number': objects.asset_serial_number} data = NewAssetDeliveredByProjectTbl.add(data, auth['group'], None) if data.success: data = list( UnassignedAssetsView.objects.filter(pk=data.obj_id)) return InsertChangeUnassignedAssetView(returning=data) raise GraphQLError(data.readable_message())
def mutate(root, info, where=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) data = { 'asset_id': where.id._eq, } result = list(UnassignedAssetsView.objects.filter(pk=where.id._eq)) data = remove_asset(data, auth) if data.success: return DeleteChangeUnassignedAssetView(returning=result) raise GraphQLError(data.readable_message())
def mutate(root, info, where=None, _set=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) if not _set.reserved is None: data = {'id': where.id._eq, 'reserved': _set.reserved} data = ReserveEntityUtil(data, auth) elif not _set.approved is None: data = {'id': where.id._eq, 'approved': _set.approved} data = ApproveReservationUtil(data, auth) else: raise GraphQLError('Unimplemented') if data['result'] == 0: data = ReservationView.objects.filter(pk=data['errors']) return UpdateReserView(returning=data) raise GraphQLError(data['errors'])
def mutate(root, info, where=None, _set=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) data = { 'role_id': _set.role_id, 'asset_id': where.id._eq, } result = list(UnassignedAssetsView.objects.filter( pk=where.id._eq)) # be optimistic # django orm queries are lazy (ie doesnt run until data is used) since data will no longer exist after we need to do something with it first # since we need to return a list with the object we deleted we can get the object before we delete it if _set.role_id == 3: data = remove_asset(data, auth) else: data = assign_asset_to_role_change(data, auth) if data.success: return UpdateChangeUnassignedAssetView(returning=result) raise GraphQLError(data.readable_message())
def mutate(root, info, where=None, _set=None): with transaction.atomic(): auth = AuthenticationUtil(info) if not auth['valid']: raise GraphQLError( 'User / Client is not properly authenticated. Please Login.' ) if not where.id is None: # delete role role_id = where.id._eq result = ChangeView.objects.filter(pk=where.id._eq) data = remove_change(role_id, auth) elif not where.asset_id is None: # delete asset asset_id = where.asset_id._eq result = ChangeView.objects.filter(pk=where.asset_id._eq) data = remove_asset( { 'asset_id': asset_id, 'view': ReconciliationView, }, auth) if data.success: data = ChangeView.objects.filter(pk=data.obj_id) return DeleteChangeView(returning=(data if data else result)) raise GraphQLError(data.readable_message())
def resolve_project_details(self, info, where=None): if not where: return [ProjectDetails()] auth = AuthenticationUtil(info) return [project_details(where.id._eq)]
def resolve_user_projects(self, info, **kwargs): auth = AuthenticationUtil(info) return user_projects(auth['user_id'])