Example #1
0
 def test_parent_filter_excludes_linked_nodes(self):
     linked_node = NodeFactory()
     self.node_A.add_node_link(linked_node, auth=Auth(self.user))
     expected = [self.node_B1._id, self.node_B2._id]
     res = self.app.get('{}{}'.format(self.parent_url, self.node_A._id), auth=self.user.auth)
     actual = [node['id'] for node in res.json['data']]
     assert_not_in(linked_node._id, actual)
     assert_equal(set(expected), set(actual))
Example #2
0
    def test_tag_filter(self):
        self.node_A.add_tag('nerd', auth=Auth(self.node_A.creator), save=True)
        expected = [self.node_A._id]
        res = self.app.get('{}nerd'.format(self.tags_url), auth=self.user.auth)
        actual = [node['id'] for node in res.json['data']]
        assert_equal(expected, actual)

        res = self.app.get('{}bird'.format(self.tags_url), auth=self.user.auth)
        actual = [node['id'] for node in res.json['data']]
        assert_equal([], actual)
Example #3
0
    def test_tag_filter(self, app, user, parent_project, tags_url):
        parent_project.add_tag('reason',
                               auth=Auth(parent_project.creator),
                               save=True)
        expected = [parent_project._id]
        res = app.get('{}reason'.format(tags_url), auth=user.auth)
        actual = [node['id'] for node in res.json['data']]
        assert expected == actual

        res = app.get('{}bird'.format(tags_url), auth=user.auth)
        actual = [node['id'] for node in res.json['data']]
        assert [] == actual
Example #4
0
 def test_parent_filter_excludes_linked_nodes(self, app, user,
                                              parent_project,
                                              child_node_one,
                                              child_node_two, parent_url):
     linked_node = NodeFactory()
     parent_project.add_node_link(linked_node, auth=Auth(user))
     expected = [child_node_one._id, child_node_two._id]
     res = app.get('{}{}'.format(parent_url, parent_project._id),
                   auth=user.auth)
     actual = [node['id'] for node in res.json['data']]
     assert linked_node._id not in actual
     assert set(expected) == set(actual)
Example #5
0
    def check_in_or_out(self, user, checkout, save=False):
        """
        Updates self.checkout with the requesting user or None,
        iff user has permission to check out file or folder.
        Adds log to self.node.


        :param user:        User making the request
        :param checkout:    Either the same user or None, depending on in/out-checking
        :param save:        Whether or not to save the user
        """
        from osf.models import NodeLog  # Avoid circular import

        if (
                self.is_checked_out and self.checkout != user and permissions.ADMIN not in self.node.get_permissions(
                user)) \
                or permissions.WRITE not in self.node.get_permissions(user):
            raise exceptions.FileNodeCheckedOutError()

        action = NodeLog.CHECKED_OUT if checkout else NodeLog.CHECKED_IN

        if self.is_checked_out and action == NodeLog.CHECKED_IN or not self.is_checked_out and action == NodeLog.CHECKED_OUT:
            self.checkout = checkout

            self.node.add_log(
                action=action,
                params={
                    'kind': self.kind,
                    'project': self.node.parent_id,
                    'node': self.node._id,
                    'urls': {
                        # web_url_for unavailable -- called from within the API, so no flask app
                        'download':
                        '/project/{}/files/{}/{}/?action=download'.format(
                            self.node._id, self.provider, self._id),
                        'view':
                        '/project/{}/files/{}/{}'.format(
                            self.node._id, self.provider, self._id)
                    },
                    'path': self.materialized_path
                },
                auth=Auth(user),
            )

            if save:
                self.save()