Exemple #1
0
 def delete(self, request, *args, **kwargs):
     try:
         node, user = self.get_object()
         if node.remove_contributor(user, None, log=False):
             update_admin_log(
                 user_id=self.request.user.id,
                 object_id=node.pk,
                 object_repr='Contributor',
                 message='User {} removed from node {}.'.format(
                     user.pk, node.pk),
                 action_flag=CONTRIBUTOR_REMOVED)
             # Log invisibly on the OSF.
             osf_log = NodeLog(
                 action=NodeLog.CONTRIB_REMOVED,
                 user=None,
                 params={
                     'project': node.parent_id,
                     'node': node.pk,
                     'contributors': user.pk
                 },
                 date=timezone.now(),
                 should_hide=True,
             )
             osf_log.save()
     except AttributeError:
         return page_not_found(
             request,
             AttributeError('{} with id "{}" not found.'.format(
                 self.context_object_name.title(), kwargs.get('node_id'))))
     return redirect(reverse_node(self.kwargs.get('node_id')))
Exemple #2
0
 def delete(self, request, *args, **kwargs):
     try:
         node = self.get_object()
         flag = None
         osf_flag = None
         message = None
         if node.is_deleted:
             node.is_deleted = False
             node.deleted_date = None
             node.deleted = None
             flag = NODE_RESTORED
             message = 'Node {} restored.'.format(node.pk)
             osf_flag = NodeLog.NODE_CREATED
         elif not node.is_registration:
             node.is_deleted = True
             node.deleted = timezone.now()
             node.deleted_date = node.deleted
             flag = NODE_REMOVED
             message = 'Node {} removed.'.format(node.pk)
             osf_flag = NodeLog.NODE_REMOVED
         node.save()
         if flag is not None:
             update_admin_log(
                 user_id=self.request.user.id,
                 object_id=node.pk,
                 object_repr='Node',
                 message=message,
                 action_flag=flag
             )
         if osf_flag is not None:
             # Log invisibly on the OSF.
             osf_log = NodeLog(
                 action=osf_flag,
                 user=None,
                 params={
                     'project': node.parent_id,
                 },
                 date=timezone.now(),
                 should_hide=True,
             )
             osf_log.save()
     except AttributeError:
         return page_not_found(
             request,
             AttributeError(
                 '{} with id "{}" not found.'.format(
                     self.context_object_name.title(),
                     kwargs.get('guid')
                 )
             )
         )
     return redirect(reverse_node(self.kwargs.get('guid')))
Exemple #3
0
 def add_contributor_removed_log(self, node, user):
     osf_log = NodeLog(
         action=NodeLog.CONTRIB_REMOVED,
         user=None,
         params={
             'project': node.parent_id,
             'node': node.pk,
             'contributors': user.pk
         },
         date=timezone.now(),
         should_hide=True,
     )
     return osf_log.save()
Exemple #4
0
 def add_contributor_removed_log(self, node, user):
     osf_log = NodeLog(
         action=NodeLog.CONTRIB_REMOVED,
         user=None,
         params={
             'project': node.parent_id,
             'node': node.pk,
             'contributors': user.pk
         },
         date=timezone.now(),
         should_hide=True,
     )
     return osf_log.save()
Exemple #5
0
 def delete(self, request, *args, **kwargs):
     try:
         node = self.get_object()
         flag = None
         osf_flag = None
         message = None
         if node.is_deleted:
             node.is_deleted = False
             node.deleted_date = None
             flag = NODE_RESTORED
             message = 'Node {} restored.'.format(node.pk)
             osf_flag = NodeLog.NODE_CREATED
         elif not node.is_registration:
             node.is_deleted = True
             node.deleted_date = timezone.now()
             flag = NODE_REMOVED
             message = 'Node {} removed.'.format(node.pk)
             osf_flag = NodeLog.NODE_REMOVED
         node.save()
         if flag is not None:
             update_admin_log(
                 user_id=self.request.user.id,
                 object_id=node.pk,
                 object_repr='Node',
                 message=message,
                 action_flag=flag
             )
         if osf_flag is not None:
             # Log invisibly on the OSF.
             osf_log = NodeLog(
                 action=osf_flag,
                 user=None,
                 params={
                     'project': node.parent_id,
                 },
                 date=timezone.now(),
                 should_hide=True,
             )
             osf_log.save()
     except AttributeError:
         return page_not_found(
             request,
             AttributeError(
                 '{} with id "{}" not found.'.format(
                     self.context_object_name.title(),
                     kwargs.get('guid')
                 )
             )
         )
     return redirect(reverse_node(self.kwargs.get('guid')))
Exemple #6
0
def count_user_logs(user):
    logs = NodeLog.find(Q('user', 'eq', user._id))
    length = logs.count()
    if length == LOG_THRESHOLD:
        item = logs[0]
        if item.action == 'project_created' and item.node.is_bookmark_collection:
            length -= 1
    return length
Exemple #7
0
def count_user_logs(user):
    logs = NodeLog.find(Q('user', 'eq', user._id))
    length = logs.count()
    if length == LOG_THRESHOLD:
        item = logs[0]
        if item.action == 'project_created' and item.node.is_bookmark_collection:
            length -= 1
    return length
Exemple #8
0
    def get_log(self):
        log = NodeLog.load(self.kwargs.get('log_id'))
        if not log:
            raise NotFound(
                detail='No log matching that log_id could be found.')

        self.check_object_permissions(self.request, log)
        return log
Exemple #9
0
    def get_log(self):
        log = NodeLog.load(self.kwargs.get('log_id'))
        if not log:
            raise NotFound(
                detail='No log matching that log_id could be found.',
            )

        self.check_object_permissions(self.request, log)
        return log
Exemple #10
0
    def post(self, request, *args, **kwargs):
        node = self.get_object()
        if node.is_deleted:
            node.is_deleted = False
            node.deleted_date = None
            node.deleted = None
            update_admin_log(user_id=self.request.user.id,
                             object_id=node.pk,
                             object_repr='Node',
                             message=f'Node {node.pk} restored.',
                             action_flag=NODE_RESTORED)
            NodeLog(
                action=NodeLog.NODE_CREATED,
                user=None,
                params={
                    'project': node.parent_id,
                },
                date=timezone.now(),
                should_hide=True,
            ).save()
        else:
            node.is_deleted = True
            node.deleted = timezone.now()
            node.deleted_date = node.deleted
            update_admin_log(user_id=self.request.user.id,
                             object_id=node.pk,
                             object_repr='Node',
                             message=f'Node {node.pk} removed.',
                             action_flag=NODE_REMOVED)
            NodeLog(
                action=NodeLog.NODE_REMOVED,
                user=None,
                params={
                    'project': node.parent_id,
                },
                date=timezone.now(),
                should_hide=True,
            ).save()
        node.save()

        return redirect(self.get_success_url())
Exemple #11
0
 def delete(self, request, *args, **kwargs):
     try:
         node, user = self.get_object()
         if node.remove_contributor(user, None, log=False):
             update_admin_log(
                 user_id=self.request.user.id,
                 object_id=node.pk,
                 object_repr='Contributor',
                 message='User {} removed from node {}.'.format(
                     user.pk, node.pk
                 ),
                 action_flag=CONTRIBUTOR_REMOVED
             )
             # Log invisibly on the OSF.
             osf_log = NodeLog(
                 action=NodeLog.CONTRIB_REMOVED,
                 user=None,
                 params={
                     'project': node.parent_id,
                     'node': node.pk,
                     'contributors': user.pk
                 },
                 date=timezone.now(),
                 should_hide=True,
             )
             osf_log.save()
     except AttributeError:
         return page_not_found(
             request,
             AttributeError(
                 '{} with id "{}" not found.'.format(
                     self.context_object_name.title(),
                     kwargs.get('node_id')
                 )
             )
         )
     return redirect(reverse_node(self.kwargs.get('node_id')))
Exemple #12
0
def logs_since(user, date):
    return NodeLog.find(
        Q('user', 'eq', user._id) &
        Q('date', 'gt', date)
    )