Repository: kartoza/prj.app

Issue:
Bug in version acceptance for pending project
# Problem

When project is still in pending, we cannot see the page. On the pending version, we could add new version and approve it. That make the url for project is not found but the version is there.
# Proposed solution

Validator for approving version (and also entry) if the project is not approved yet



Discussion:

Resolving patch:
diff --git a/django_project/base/views/project.py b/django_project/base/views/project.py
--- a/django_project/base/views/project.py
+++ b/django_project/base/views/project.py
@@ -181,7 +181,10 @@ def get_queryset(self):
             return qs.filter(owner=self.request.user)
 
     def get_success_url(self):
-        return reverse('project-detail', kwargs={'slug': self.object.slug})
+        if self.object.approved:
+            return reverse('project-detail', kwargs={'slug': self.object.slug})
+        else:
+            return reverse('pending-project-list')
 
     def form_valid(self, form):
         """Check that there is no referential integrity error when saving."""
diff --git a/django_project/changes/models/version.py b/django_project/changes/models/version.py
--- a/django_project/changes/models/version.py
+++ b/django_project/changes/models/version.py
@@ -4,13 +4,13 @@
 from common.utilities import version_slugify
 import os
 import logging
-from core.settings.contrib import STOP_WORDS
-from django.conf.global_settings import MEDIA_ROOT
-from django.db import models
 from .entry import Entry
 from .sponsorship_period import SponsorshipPeriod
+from core.settings.contrib import STOP_WORDS
+from django.conf.global_settings import MEDIA_ROOT
 from django.contrib.auth.models import User
 from django.utils.translation import ugettext_lazy as _
+from django.db import models
 
 logger = logging.getLogger(__name__)
 
diff --git a/django_project/changes/views/version.py b/django_project/changes/views/version.py
--- a/django_project/changes/views/version.py
+++ b/django_project/changes/views/version.py
@@ -141,6 +141,13 @@ def get_object(self, queryset=None):
                     'Requested project does not exist.')
             try:
                 obj = queryset.filter(project=project).get(slug=slug)
+                if not obj.approved:
+                    raise Http404(
+                        'Sorry! The project you are requesting a version for '
+                        'could not be found or you do not have permission to '
+                        'view the version. Also the version may not be '
+                        'approved yet. Try logging in as a staff member if '
+                        'you wish to view it.')
                 return obj
             except Version.DoesNotExist:
                 raise Http404(
@@ -515,7 +522,8 @@ def get_redirect_url(self, project_slug, slug):
         :returns: A url.
         :rtype: str
         """
-        project = Project.objects.get(slug=project_slug)
+        project = Project.objects.filter(slug=project_slug)
+        project = get_object_or_404(project, approved=True)
         version_qs = Version.unapproved_objects.filter(project=project)
         version = get_object_or_404(version_qs, slug=slug)
         version.approved = True


Test patch: