def test_create_anonymous_private_link_log(self): node = NodeFactory() new_private_link(name='wooo', user=node.creator, nodes=[node], anonymous=True) last_log = node.logs.latest() assert last_log.action == NodeLog.VIEW_ONLY_LINK_ADDED assert last_log.params == { 'node': node._id, 'project': node.parent_node._id, 'anonymous_link': True, 'user': node.creator._id }
def project_generate_private_link_post(auth, node, **kwargs): """ creata a new private link object and add it to the node and its selected children""" node_ids = request.json.get('node_ids', []) name = request.json.get('name', '') anonymous = request.json.get('anonymous', False) if node._id not in node_ids: node_ids.insert(0, node._id) nodes = [Node.load(node_id) for node_id in node_ids] has_public_node = any(node.is_public for node in nodes) new_link = new_private_link( name=name, user=auth.user, nodes=nodes, anonymous=anonymous ) if anonymous and has_public_node: status.push_status_message( 'Anonymized view-only links <b>DO NOT</b> ' 'anonymize contributors of public project or component.' ) return new_link
def project_generate_private_link_post(auth, node, **kwargs): """ creata a new private link object and add it to the node and its selected children""" node_ids = request.json.get('node_ids', []) name = request.json.get('name', '') anonymous = request.json.get('anonymous', False) if node._id not in node_ids: node_ids.insert(0, node._id) nodes = [Node.load(node_id) for node_id in node_ids] has_public_node = any(node.is_public for node in nodes) new_link = new_private_link(name=name, user=auth.user, nodes=nodes, anonymous=anonymous) if anonymous and has_public_node: status.push_status_message( 'Anonymized view-only links <b>DO NOT</b> ' 'anonymize contributors of public project or component.') return new_link
def project_generate_private_link_post(auth, node, **kwargs): """ creata a new private link object and add it to the node and its selected children""" node_ids = request.json.get('node_ids', []) name = request.json.get('name', '') anonymous = request.json.get('anonymous', False) if node._id not in node_ids: node_ids.insert(0, node._id) nodes = [Node.load(node_id) for node_id in node_ids] has_public_node = any(node.is_public for node in nodes) try: new_link = new_private_link( name=name, user=auth.user, nodes=nodes, anonymous=anonymous ) except ValidationValueError as e: raise HTTPError( http.BAD_REQUEST, data=dict(message_long=e.message) ) if anonymous and has_public_node: status.push_status_message( 'Anonymized view-only links <b>DO NOT</b> ' 'anonymize contributors of public projects or components.', trust=True ) return new_link
def test_create_anonymous_private_link_log(self): node = NodeFactory() new_private_link( name='wooo', user=node.creator, nodes=[node], anonymous=True ) last_log = node.logs.latest() assert last_log.action == NodeLog.VIEW_ONLY_LINK_ADDED assert last_log.params == { 'node': node._id, 'project': node.parent_node._id, 'anonymous_link': True, 'user': node.creator._id }
def create(self, validated_data): name = validated_data.pop('name') user = get_user_auth(self.context['request']).user anonymous = validated_data.pop('anonymous') node = self.context['view'].get_node() try: view_only_link = new_private_link(name=name, user=user, nodes=[node], anonymous=anonymous) except ValidationValueError: raise exceptions.ValidationError('Invalid link name.') return view_only_link
def create(self, validated_data): name = validated_data.pop('name') user = get_user_auth(self.context['request']).user anonymous = validated_data.pop('anonymous') node = self.context['view'].get_node() try: view_only_link = new_private_link( name=name, user=user, nodes=[node], anonymous=anonymous ) except ValidationValueError: raise exceptions.ValidationError('Invalid link name.') return view_only_link
def project_generate_private_link_post(auth, node, **kwargs): """ creata a new private link object and add it to the node and its selected children""" node_ids = request.json.get("node_ids", []) name = request.json.get("name", "") anonymous = request.json.get("anonymous", False) if node._id not in node_ids: node_ids.insert(0, node._id) nodes = [Node.load(node_id) for node_id in node_ids] try: new_link = new_private_link(name=name, user=auth.user, nodes=nodes, anonymous=anonymous) except ValidationValueError as e: raise HTTPError(http.BAD_REQUEST, data=dict(message_long=e.message)) return new_link
def project_generate_private_link_post(auth, node, **kwargs): """ creata a new private link object and add it to the node and its selected children""" node_ids = request.json.get('node_ids', []) name = request.json.get('name', '') anonymous = request.json.get('anonymous', False) if node._id not in node_ids: node_ids.insert(0, node._id) nodes = [AbstractNode.load(node_id) for node_id in node_ids] try: new_link = new_private_link(name=name, user=auth.user, nodes=nodes, anonymous=anonymous) except ValidationError as e: raise HTTPError(http.BAD_REQUEST, data=dict(message_long=e.message)) return new_link
def test_not_has_permission_read_has_link(self): link = new_private_link('red-special', self.user, [self.node], anonymous=False) views.check_access(self.node, Auth(private_key=link.key), 'download', None)