コード例 #1
0
ファイル: views.py プロジェクト: erinspace/osf.io
 def get_object(self):
     link_id = self.kwargs['link_id']
     view_only_link = PrivateLink.load(link_id)
     return {
         'data': view_only_link.nodes.all(),
         'self': view_only_link
     }
コード例 #2
0
 def get_object(self):
     link_id = self.kwargs['link_id']
     view_only_link = PrivateLink.load(link_id)
     return {
         'data': view_only_link.nodes.all(),
         'self': view_only_link,
     }
コード例 #3
0
 def get_serializer_class(self):
     if 'link_id' in self.kwargs:
         view_only_link = PrivateLink.load(self.kwargs['link_id'])
         node = view_only_link.nodes.first()
         if node.is_registration:
             return RegistrationSerializer
         return NodeSerializer
     else:
         return JSONAPISerializer
コード例 #4
0
ファイル: views.py プロジェクト: erinspace/osf.io
 def get_serializer_class(self):
     if 'link_id' in self.kwargs:
         view_only_link = PrivateLink.load(self.kwargs['link_id'])
         node = view_only_link.nodes.first()
         if node.is_registration:
             return RegistrationSerializer
         return NodeSerializer
     else:
         return JSONAPISerializer
コード例 #5
0
    def get_queryset(self):
        link_id = self.kwargs['link_id']
        view_only_link = PrivateLink.load(link_id)
        user = get_user_auth(self.request).user

        nodes = []
        for node in view_only_link.nodes.all():
            if not node.has_permission(user, ADMIN):
                raise PermissionDenied
            nodes.append(node)

        return nodes
コード例 #6
0
ファイル: views.py プロジェクト: erinspace/osf.io
    def get_queryset(self):
        link_id = self.kwargs['link_id']
        view_only_link = PrivateLink.load(link_id)
        user = get_user_auth(self.request).user

        nodes = []
        for node in view_only_link.nodes.all():
            if not node.has_permission(user, 'admin'):
                raise PermissionDenied
            nodes.append(node)

        return nodes
コード例 #7
0
    def get_object(self):
        link_id = self.kwargs['link_id']
        view_only_link = PrivateLink.load(link_id)
        user = get_user_auth(self.request).user

        for node in view_only_link.nodes.all():
            if not node.has_permission(user, ADMIN):
                raise PermissionDenied

        if not view_only_link:
            raise NotFound

        return view_only_link
コード例 #8
0
ファイル: views.py プロジェクト: erinspace/osf.io
    def get_object(self):
        link_id = self.kwargs['link_id']
        view_only_link = PrivateLink.load(link_id)
        user = get_user_auth(self.request).user

        for node in view_only_link.nodes.all():
            if not node.has_permission(user, 'admin'):
                raise PermissionDenied

        if not view_only_link:
            raise NotFound

        return view_only_link
コード例 #9
0
def project_private_link_edit(auth, **kwargs):
    name = request.json.get('value', '')
    try:
        validate_title(name)
    except ValidationError as e:
        message = 'Invalid link name.' if e.message == 'Invalid title.' else e.message
        raise HTTPError(http.BAD_REQUEST, data=dict(message_long=message))

    private_link_id = request.json.get('pk', '')
    private_link = PrivateLink.load(private_link_id)

    if private_link:
        new_name = strip_html(name)
        private_link.name = new_name
        private_link.save()
        return new_name
    else:
        raise HTTPError(http.BAD_REQUEST,
                        data=dict(message_long='View-only link not found.'))
コード例 #10
0
def remove_private_link(*args, **kwargs):
    link_id = request.json['private_link_id']

    try:
        link = PrivateLink.load(link_id)
        link.is_deleted = True
        link.save()

        for node in link.nodes.all():
            log_dict = {
                'project': node.parent_id,
                'node': node._id,
                'user': kwargs.get('auth').user._id,
                'anonymous_link': link.anonymous,
            }

            node.add_log(NodeLog.VIEW_ONLY_LINK_REMOVED,
                         log_dict,
                         auth=kwargs.get('auth', None))

    except ModularOdmException:
        raise HTTPError(http.NOT_FOUND)
コード例 #11
0
ファイル: node.py プロジェクト: adlius/osf.io
def project_private_link_edit(auth, **kwargs):
    name = request.json.get('value', '')
    try:
        validate_title(name)
    except ValidationError as e:
        message = 'Invalid link name.' if e.message == 'Invalid title.' else e.message
        raise HTTPError(
            http.BAD_REQUEST,
            data=dict(message_long=message)
        )

    private_link_id = request.json.get('pk', '')
    private_link = PrivateLink.load(private_link_id)

    if private_link:
        new_name = strip_html(name)
        private_link.name = new_name
        private_link.save()
        return new_name
    else:
        raise HTTPError(
            http.BAD_REQUEST,
            data=dict(message_long='View-only link not found.')
        )
コード例 #12
0
ファイル: node.py プロジェクト: adlius/osf.io
def remove_private_link(*args, **kwargs):
    link_id = request.json['private_link_id']

    try:
        link = PrivateLink.load(link_id)
        link.is_deleted = True
        link.save()

        for node in link.nodes.all():
            log_dict = {
                'project': node.parent_id,
                'node': node._id,
                'user': kwargs.get('auth').user._id,
                'anonymous_link': link.anonymous,
            }

            node.add_log(
                NodeLog.VIEW_ONLY_LINK_REMOVED,
                log_dict,
                auth=kwargs.get('auth', None)
            )

    except ModularOdmException:
        raise HTTPError(http.NOT_FOUND)