def post(self, request, *args, **kwargs): """ Handle the claim_url postback when the user has completed the claim setup """ signature_request_id = request.POST.get('signature_request_id') subject = request.POST.get('subject', None) # HS to rpovide these, currently missing message = request.POST.get('message', None) # HS to rpovide these, currently missing logger.info('found signature_request_id: %s' % signature_request_id) self.object = self.get_object() object_signature_request = self.object.signing_request # Get the HelloSignReqeust object for this SignDocument if not object_signature_request or object_signature_request.signature_request_id != signature_request_id: logger.error('signature_request_id did not match for %s self.object.signing_request: %s != %s' % (self.object.signing_request, self.object.signing_request.signature_request_id, signature_request_id)) raise Http404 # set the is_claimed property object_signature_request.data['is_claimed'] = True object_signature_request.save(update_fields=['data']) # # Perform the document send for signing and the email process async # run_task(_send_for_signing, from_user=request.user, sign_object=self.object, signature_request_id=signature_request_id, subject=subject, message=message) # send log event self.matter.actions.completed_setup_for_signing(user=request.user, sign_object=self.object) return super(ClaimSignRevisionView, self).post(request=request, *args, **kwargs)
def realtime_event(self, event, obj, ident, from_user=None, **kwargs): """ Send a realtime pusher event Semi-ironic as we need to have a fake delay to ensure that the update gets through can perhaps be solved with chaining http://docs.celeryproject.org/en/latest/userguide/canvas.html#chains """ from_ident = None # only set it if we have a from_user if hasattr(from_user, 'username'): from_ident = from_user.username # # Run async realtime_matter_event pusher # run_task(realtime_matter_event, matter=self.matter, event=event, obj=obj, ident=ident, from_ident=from_ident, countdown=5, # Delay by set 5 seconds before sending event **kwargs)
def export_matter(self, requested_by, provider=None): from toolkit.tasks import run_task from toolkit.apps.matter.tasks import _export_matter # # Reset Pending Export # export_info = self.export_info export_info.update( { "provider": provider, "is_pending_export": True, "last_export_requested": datetime.datetime.utcnow().isoformat(), "last_export_requested_by": requested_by.get_full_name(), } ) self.save(update_fields=["data"]) # start the process run_task(_export_matter, matter=self, requested_by=requested_by, provider=provider) # record the event self.actions.started_matter_export(user=requested_by)
def on_hellosign_webhook_event_recieved(sender, hellosign_log, signature_request_id, hellosign_request, event_type, data, **kwargs): # # Head the signal # signature_doc = hellosign_request.source_object if signature_doc.__class__.__name__ in ['SignDocument']: logging.info('Recieved event: %s for request: %s' % (event_type, hellosign_request,)) # # ALL HAVE SIGNED # if event_type == 'signature_request_all_signed': logging.info('Recieved signature_request_all_signed from HelloSign, downloading file for attachment as final') # update request _update_signature_request(hellosign_request=hellosign_request, data=data) # Send event hellosign_request.source_object.document.item.matter.actions.all_users_have_signed(sign_object=hellosign_request.source_object) # # Download the file and update the item.latest_revision # run_task(_download_signing_complete_document, hellosign_request=hellosign_request, data=data) # # USER SIGNED # if event_type == 'signature_request_signed': logging.info('Recieved signature_request_signed from HelloSign, sending event notice') # update the signature_request data with our newly provided data _update_signature_request(hellosign_request=hellosign_request, data=data) # Send event user = _get_user_from_event_data(event_data=data) if user: hellosign_request.source_object.document.item.matter.actions.user_signed(user=user, sign_object=hellosign_request.source_object) # update the open requests count for the user profile = user.profile profile.open_requests = profile.get_open_requests_count() profile.save(update_fields=['data']) if event_type == 'signature_request_viewed': # # NOT HANDLED HERE rather in toolkit.api.views.sign # REASON: because the lawyer can view signature requests at their # distinct urls and may not actually be the invited signer # # user = _get_user_from_event_data(event_data=data) # if user: # revision = hellosign_request.source_object.document # item = revision.item # matter = item.matter # matter.actions.user_viewed_signature_request(item=revision.item, # user=user, # revision=revision) pass
def on_activity_received(sender, **kwargs): # actor has to be popped, the rest has to remain in kwargs and is not used here, except message to use in abridge actor = kwargs.pop('actor', False) kwargs.pop('signal', None) # Gets verb = kwargs.get('verb', False) action_object = kwargs.get('action_object', False) target = kwargs.get('target', False) reviewdocument = kwargs.get('reviewdocument', False) send_to_all = kwargs.get('send_to_all', False) message = kwargs.get('message', False) # # allow us to override the generic message passed in # if kwargs.get('override_message') not in [None, '']: # # @BUSINESSRULE must override the "message" key here # but preserve original_message # kwargs['original_message'] = kwargs['message'] # preserve message = kwargs.get('override_message') # override the message kwargs['message'] = message verb_slug = kwargs.get('verb_slug', False) # # Ugly default message # if not message: message = u'%s %s %s' % (actor, verb, action_object) # # Test that we have the required arguments to send the action signal # if actor and action_object and target and verb_slug: # send to django-activity-stream # note the kwarg.pop so that they dont get sent in as kwargs # skip_async = True means the activity will be added synchronously run_task(_activity_send, actor=actor, target=kwargs.pop('target', None), action_object=kwargs.pop('action_object', None), message=kwargs.pop('message', None), **kwargs) # send the notifications to the participants run_task(_notifications_send, verb_slug=verb_slug, actor=actor, target=target, action_object=action_object, message=message, comment=kwargs.get('comment', None), item=kwargs.get('item', None), reviewdocument=reviewdocument, send_to_all=send_to_all) # send to abridge service run_task(_abridge_send, verb_slug=verb_slug, actor=actor, target=target, action_object=action_object, message=message, comment=kwargs.get('comment', None), item=kwargs.get('item', None), reviewdocument=reviewdocument, send_to_all=send_to_all) # send the @username mentions run_task(_mentions_send, actor=actor, action_object=action_object, text=kwargs.get('comment', message)) else: logger.error('One or more or actor: {actor} action_object: {action_object} target: {target} verb_slug: {verb_slug} where not provided'.format(actor=actor, action_object=action_object, target=target, verb_slug=verb_slug))
def _notifications_send(verb_slug, actor, target, action_object, message, comment, item, reviewdocument, send_to_all=False): """ Send persistent messages (notifications) for this user github notifications style stored_messages.STORED_DEBUG, stored_messages.STORED_INFO, stored_messages.STORED_SUCCESS, stored_messages.STORED_WARNING, stored_messages.STORED_ERROR update the user.profile.has_notifications """ if verb_slug in NOTIFICATIONS_WHITELIST: # catch when we have no stored message if stored_messages is None: logger.critical('django-stored-messages is not installed') return None if message: from toolkit.api.serializers.user import LiteUserSerializer query_set = target.participants.select_related('profile') # # If we are not sending this message to all participants then exclude the originator # if send_to_all is False: query_set = query_set.exclude(id=actor.pk) # Because we cant mixn the ApiMixin class ot the django User Object actor = LiteUserSerializer(actor, context={'request': None}).data if hasattr(action_object, 'api_serializer') is True: action_object = action_object.api_serializer(action_object, context={'request': None}).data if hasattr(item, 'api_serializer') is True: item = item.api_serializer(item, context={'request': None}).data if hasattr(reviewdocument, 'api_serializer') is True: reviewdocument = reviewdocument.api_serializer(item, context={'request': None}).data target_class_name = target.__class__.__name__ if target_class_name == 'Workspace': target = target.api_serializer(target, context={'request': None}).data else: raise Exception('Unknown target_class_name: %s' % target_class_name) stored_messages.add_message_for(users=query_set.all(), level=stored_messages.STORED_INFO, message=message, extra_tags='', fail_silently=False, verb_slug=verb_slug, actor=actor, action_object=action_object, target=target, comment=comment, item=item, reviewdocument=reviewdocument) # # @TODO move into manager? # for u in query_set.exclude(profile__has_notifications=True): profile = u.profile profile.has_notifications = True profile.save(update_fields=['has_notifications']) # # Send pusher notification # for u in query_set.values('username'): run_task(youve_got_notifications, username=u.get('username'), event='notifications.new')