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 }
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, }
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
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
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
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
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
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.'))
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)
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.') )
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)