示例#1
0
def add_folder(request, revision_id):
    " adds an EmptyDir to a revision "
    revision = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if request.user.pk != revision.author.pk:
        log_msg = ("[security] Attempt to add a folder to revision (%s) by "
                   "non-owner (%s)" % (revision_id, request.user))
        log.warning(log_msg)
        return HttpResponseForbidden('You are not the author of this Package')

    foldername, root = (request.POST.get('name',
                                         ''), request.POST.get('root_dir'))

    dir = EmptyDir(name=foldername, author=request.user, root_dir=root)
    try:
        dir.save()
        revision.folder_add(dir)
    except FilenameExistException, err:
        dir.delete()
        return HttpResponseForbidden(escape(str(err)))
示例#2
0
    def test_folder_removed_when_modules_added(self):
        " EmptyDir's shouldn't exist if there are modules inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='l')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        mod = Module(filename='/'.join([self.path, 'helpers']),
                     author=self.author,
                     code='//test code')
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())

        mod = Module(filename='model', author=self.author, code='//test code')
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())