def rebuildSubscriptions(context, request): """ Rebuild context subscriptions Performs sanity checks on existing subscriptions """ existing_contexts = {} contexts = request.db.contexts.dump() for context in contexts: context.updateUsersSubscriptions(force_update=True) context.updateContextActivities(force_update=True) existing_contexts[context['hash']] = context users = request.db.users.search({'subscribedTo.0': {'$exists': True}}) for user in users: for subscription in user.get('subscribedTo', []): if subscription['hash'] not in existing_contexts: fake_deleted_context = Context.from_object(request, subscription) user.removeSubscription(fake_deleted_context) else: subscription.pop('vetos', None) subscription.pop('grants', None) user.save() handler = JSONResourceRoot(request, []) return handler.buildResponse()
def _after_delete(self): """ Deletes user exchanges just after user is deleted. """ # Comento que al borrar el usuario no borre sus exchanges del rabbit # para que no haya problemas con este usuario ens otras instancias #notifier = RabbitNotifications(self.request) #notifier.delete_user(self['username']) # Mientras no solucionamos lo anterior, como los routing key de activity no se borraban # y nos podia dar error al intentar notificar a ese usuario # borro los contextos a los que esta subscrito este usuario en este MAX from max.models import Context for subscription in self['subscribedTo']: fake_deleted_context = Context.from_object(self.request, subscription) self.removeSubscription(fake_deleted_context)
def addContext(contexts, request): """ Adds a context """ # Initialize a Context object from the request newcontext = Context.from_request(request) # If we have the _id setted, then the object already existed in the DB, # otherwise, proceed to insert it into the DB # In both cases, respond with the JSON of the object and the appropiate # HTTP Status Code if newcontext.get('_id'): # Already Exists code = 200 else: # New context code = 201 contextid = newcontext.insert() newcontext['_id'] = contextid handler = JSONResourceEntity(request, newcontext.flatten(), status_code=code) return handler.buildResponse()
def addContext(context, request): """ """ # Initialize a Context object from the request newcontext = Context() newcontext.fromRequest(request) # If we have the _id setted, then the object already existed in the DB, # otherwise, proceed to insert it into the DB # In both cases, respond with the JSON of the object and the appropiate # HTTP Status Code if newcontext.get('_id'): # Already Exists code = 200 else: # New User code = 201 contextid = newcontext.insert() newcontext['_id'] = contextid handler = JSONResourceEntity(newcontext.flatten(), status_code=code) return handler.buildResponse()