def on_consignment_withdraw(sender, prev_owner, new_owner, edition, *args, **kwargs): logger.info('SIGNAL on_consignment_withdraw') ActionControl.objects.get(user=new_owner, piece=edition.parent, edition=edition).delete() ActionControl.set_acl_transferee(user=prev_owner, edition=edition)
def on_ownership_transfer_withdraw(sender, instance, *args, **kwargs): logger.info('SIGNAL on_ownership_transfer_withdraw') ActionControl.set_acl_transferee(edition=instance.edition, user=instance.prev_owner) ActionControl.objects.get(user=instance.new_owner, piece=instance.edition.parent, edition=instance.edition).delete()
def _registered_edition_alice(): from acl.models import ActionControl from ownership.models import OwnershipEditions from piece.models import Edition piece = _registered_piece_alice() alice_bitcoin_wallet = _alice_bitcoin_wallet() alice = piece.user_registered if piece.num_editions != -1: raise DynamicFixtureError( 'Expecting piece.num_editions to be "-1", not "{}"'.format( piece.num_editions) ) # piece.num_editions = 0 bitcoin_path = alice_bitcoin_wallet.create_new_address() edition = Edition.objects.create( parent=piece, bitcoin_path=bitcoin_path, edition_number=1, owner=alice, ) piece.num_editions = 1 piece.save() ownership_editions = OwnershipEditions.create( edition=piece, new_owner=alice, ) ownership_editions.save() ActionControl.set_acl_registree_edition(user=alice, edition=edition) return edition
def on_ownership_consignment_create(sender, instance, created, *args, **kwargs): if created: logger.info('SIGNAL on_ownership_consignment_create') ActionControl.set_acl_consignee(edition=instance.edition, user=instance.new_owner) ActionControl.set_acl_owner(edition=instance.edition, user=instance.prev_owner)
def on_unconsignment_create(sender, instance, *args, **kwargs): logger.info('SIGNAL on_unconsignment_create') # set acl for unconsignee ActionControl.objects.get(user=instance.prev_owner, piece=instance.edition.parent, edition=instance.edition).delete() # set acl for owner ActionControl.set_acl_transferee(user=instance.edition.owner, edition=instance.edition)
def on_ownership_transfer_create(sender, instance, created, *args, **kwargs): if created: logger.info('SIGNAL on_ownership_transfer_create') ActionControl.set_acl_transferee(edition=instance.edition, user=instance.new_owner) ActionControl.set_acl_prev_owner(edition=instance.edition, user=instance.prev_owner) # set edit to false for acl in ActionControl.objects.filter(piece=instance.edition.parent): acl.acl_edit = False acl.save()
def editions(self, request, pk=None): try: queryset = ActionControl.get_items_for_user(self.request.user, self.get_acl_filter(), classname='edition')\ .filter(parent_id=pk)\ .order_by("edition_number") except ValueError: # empty queryset queryset = Edition.objects.none() if not len(queryset): return Response({'success': False}, status=status.HTTP_404_NOT_FOUND) page = self.paginate_queryset(queryset) if page is not None: serializer = self.get_serializer(page, many=True, context={'request': request}) return self.paginator.get_paginated_response(serializer.data, name='editions') serializer = self.get_serializer(queryset, many=True, context={'request': request}) return Response({ 'success': True, 'editions': serializer.data }, status=status.HTTP_200_OK)
def get_queryset(self): if self.action in ['list']: if self.request.user == AnonymousUser(): return self.queryset.none() return ActionControl.get_items_for_user( self.request.user, acl_filter=self.get_acl_filter(), classname='edition') return Edition.objects.filter(datetime_deleted=None)
def first_edition(self, user, acl_query_params): queryset = ActionControl.get_items_for_user(user, acl_query_params, 'edition') \ .filter(parent_id=self.id) \ .order_by('edition_number') if not len(queryset): return None return { 'bitcoin_id': queryset[0].bitcoin_id, 'edition_number': queryset[0].edition_number, 'num_editions_available': len(queryset) }
def registered_edition_alice(djroot_bitcoin_wallet, registered_piece_alice, alice_bitcoin_wallet): from acl.models import ActionControl from ownership.models import OwnershipEditions from piece.models import Edition alice = alice_bitcoin_wallet.user bitcoin_path = alice_bitcoin_wallet.create_new_address() edition = Edition.objects.create( parent=registered_piece_alice, bitcoin_path=bitcoin_path, edition_number=1, owner=alice, ) registered_piece_alice.num_editions = 1 registered_piece_alice.save() ownership_editions = OwnershipEditions.create( edition=registered_piece_alice, new_owner=alice, ) ownership_editions.save() ActionControl.set_acl_registree_edition(user=alice, edition=edition) return edition
def list(self, request, classname='piece'): """ Retrieve the request actions of the pieces """ notifications = [] for item in ActionControl.get_items_for_user(self.request.user, classname=classname): notification = self.get_notification_class().get_notifications( item, self.request.user) if notification: notifications.append(self.get_notification_class()( notification, item)) serializer = self.get_serializer(notifications, many=True) return Response({ 'success': True, 'notifications': serializer.data }, status=status.HTTP_200_OK)
def on_editions_create(sender, user_registered, editions, *args, **kwargs): logger.info('SIGNAL on_editions_create') for edition in editions: db_edition = Edition.objects.get(bitcoin_path=edition.bitcoin_path) ActionControl.set_acl_registree_edition(user=user_registered, edition=db_edition)
def on_ownership_share_piece_create(sender, instance, created, *args, **kwargs): if created: logger.info('SIGNAL on_ownership_share_piece_create') ActionControl.set_piece_acl_sharee(piece=instance.piece, user=instance.new_owner)
def on_ownership_loan_create(sender, instance, created, *args, **kwargs): if created: logger.info('SIGNAL on_ownership_loan_create') ActionControl.set_acl_sharee(edition=instance.edition, user=instance.new_owner)
def get_list_queryset(user, acl_filter={}): if user == AnonymousUser(): return Piece.objects.none() return ActionControl.get_items_for_user(user, acl_filter=acl_filter)