14
14
from django .views import View
15
15
from django .views .decorators .cache import cache_page
16
16
17
- from readthedocs .builds .constants import LATEST , STABLE , EXTERNAL
17
+ from readthedocs .builds .constants import EXTERNAL , LATEST , STABLE
18
18
from readthedocs .builds .models import Version
19
19
from readthedocs .core .utils .extend import SettingsOverrideObject
20
20
from readthedocs .projects import constants
21
21
from readthedocs .projects .templatetags .projects_tags import sort_version_aware
22
22
from readthedocs .redirects .exceptions import InfiniteRedirectException
23
23
24
- from .mixins import ServeDocsMixin , ServeRedirectMixin
25
-
26
24
from .decorators import map_project_slug
25
+ from .mixins import ServeDocsMixin , ServeRedirectMixin
27
26
from .utils import _get_project_data_from_request
28
27
29
-
30
28
log = logging .getLogger (__name__ ) # noqa
31
29
32
30
@@ -266,14 +264,17 @@ def get(self, request, proxito_path, template_name='404.html'):
266
264
if default_version_slug != version_slug :
267
265
versions .append (default_version_slug )
268
266
for version_slug_404 in versions :
267
+ if not self .allowed_user (request , final_project , version_slug_404 ):
268
+ continue
269
+
270
+ storage_root_path = final_project .get_storage_path (
271
+ type_ = 'html' ,
272
+ version_slug = version_slug_404 ,
273
+ include_file = False ,
274
+ version_type = self .version_type ,
275
+ )
269
276
for tryfile in ('404.html' , '404/index.html' ):
270
- storage_root_path = final_project .get_storage_path (
271
- type_ = 'html' ,
272
- version_slug = version_slug_404 ,
273
- include_file = False ,
274
- version_type = self .version_type ,
275
- )
276
- storage_filename_path = os .path .join (storage_root_path , tryfile )
277
+ storage_filename_path = f'{ storage_root_path } /{ tryfile } '
277
278
if storage .exists (storage_filename_path ):
278
279
log .info (
279
280
'Serving custom 404.html page: [project: %s] [version: %s]' ,
@@ -307,9 +308,7 @@ def get(self, request, project):
307
308
version = project .versions .get (slug = version_slug )
308
309
309
310
no_serve_robots_txt = any ([
310
- # If project is private or,
311
- project .privacy_level == constants .PRIVATE ,
312
- # default version is private or,
311
+ # If the default version is private or,
313
312
version .privacy_level == constants .PRIVATE ,
314
313
# default version is not active or,
315
314
not version .active ,
@@ -327,7 +326,7 @@ def get(self, request, project):
327
326
include_file = False ,
328
327
version_type = self .version_type ,
329
328
)
330
- path = os . path . join ( storage_path , ' robots.txt')
329
+ path = f' { storage_path } / robots.txt'
331
330
332
331
storage = get_storage_class (settings .RTD_BUILD_MEDIA_STORAGE )()
333
332
if storage .exists (path ):
@@ -369,9 +368,7 @@ def get(self, request, project):
369
368
frequency. Starting from 1 and decreasing by 0.1 for priorities and starting
370
369
from daily, weekly to monthly for change frequency.
371
370
372
- If the project is private, the view raises ``Http404``. On the other hand,
373
- if the project is public but a version is private, this one is not included
374
- in the sitemap.
371
+ If the project doesn't have any public version, the view raises ``Http404``.
375
372
376
373
:param request: Django request object
377
374
:param project: Project instance to generate the sitemap
@@ -417,15 +414,14 @@ def changefreqs_generator():
417
414
changefreqs = ['weekly' , 'daily' ]
418
415
yield from itertools .chain (changefreqs , itertools .repeat ('monthly' ))
419
416
420
- if project .privacy_level == constants .PRIVATE :
417
+ public_versions = Version .internal .public (
418
+ project = project ,
419
+ only_active = True ,
420
+ )
421
+ if not public_versions .exists ():
421
422
raise Http404
422
423
423
- sorted_versions = sort_version_aware (
424
- Version .internal .public (
425
- project = project ,
426
- only_active = True ,
427
- ),
428
- )
424
+ sorted_versions = sort_version_aware (public_versions )
429
425
430
426
# This is a hack to swap the latest version with
431
427
# stable version to get the stable version first in the sitemap.
0 commit comments