Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
stylesheets: Remove dynamic stylesheet serving.
Browse files Browse the repository at this point in the history
Since the introduction of the media providers and the default
installation of the filesystem media provider, it's no longer necessary
for local / non-AWS installs to use dynamically served stylesheets.

This patch removes that option to reduce complexity in the stylesheet
flows.
  • Loading branch information
spladug committed Dec 1, 2014
1 parent f92936a commit 155342f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 97 deletions.
2 changes: 0 additions & 2 deletions r2/example.ini
Expand Up @@ -95,8 +95,6 @@ lounge_reddit =
# if set, this is the domain used for static files served over http and https
# if not set, no domain will be specified and relative local URLs will be used instead
static_domain =
# whether or not to put subreddit stylesheets in the media system or serve dynamically
subreddit_stylesheets_static = false

#### Ops
# if your webserver is a proxy and on a different instance on the same 10.0.0.0/8 network
Expand Down
52 changes: 9 additions & 43 deletions r2/r2/controllers/front.py
Expand Up @@ -62,7 +62,7 @@
from listingcontroller import ListingController
from oauth2 import require_oauth2_scope
from api_docs import api_doc, api_section
from pylons import c, request, response
from pylons import c, request
from r2.models.token import EmailVerificationToken
from r2.controllers.ipn import generate_blob, validate_blob, GoldException

Expand Down Expand Up @@ -450,48 +450,20 @@ def GET_newreddit(self, name):
@require_oauth2_scope("modconfig")
@api_doc(api_section.moderation, uses_site=True)
def GET_stylesheet(self):
"""Get the subreddit's current stylesheet.
This will return either the content of or a redirect to the subreddit's
current stylesheet if one exists.
"""Redirect to the subreddit's stylesheet if one exists.
See also: [/api/subreddit_stylesheet](#POST_api_subreddit_stylesheet).
"""
if g.css_killswitch:
self.abort404()

# de-stale the subreddit object so we don't poison nginx's cache
# de-stale the subreddit object so we don't poison downstream caches
if not isinstance(c.site, FakeSubreddit):
c.site = Subreddit._byID(c.site._id, data=True, stale=False)

if c.site.stylesheet_url_http:
url = Reddit.get_subreddit_stylesheet_url(c.site)
if url:
return self.redirect(url)
else:
self.abort404()

if not c.secure:
stylesheet_contents = c.site.stylesheet_contents
else:
stylesheet_contents = c.site.stylesheet_contents_secure

if stylesheet_contents:
if c.site.stylesheet_modified:
self.abort_if_not_modified(
c.site.stylesheet_modified,
private=False,
max_age=timedelta(days=7),
must_revalidate=False,
)

response.content_type = 'text/css'
if c.site.type == 'private':
response.headers['X-Private-Subreddit'] = 'private'
return stylesheet_contents
url = Reddit.get_subreddit_stylesheet_url(c.site)
if url:
return self.redirect(url)
else:
return self.abort404()
self.abort404()

def _make_moderationlog(self, srs, num, after, reverse, count, mod=None, action=None):
query = Subreddit.get_modactions(srs, mod=mod, action=action)
Expand Down Expand Up @@ -685,20 +657,14 @@ def _edit_normal_reddit(self, location, created):
elif (location == 'stylesheet'
and c.site.can_change_stylesheet(c.user)
and not g.css_killswitch):
if hasattr(c.site,'stylesheet_contents_user') and c.site.stylesheet_contents_user:
stylesheet_contents = c.site.stylesheet_contents_user
elif hasattr(c.site,'stylesheet_contents') and c.site.stylesheet_contents:
stylesheet_contents = c.site.stylesheet_contents
else:
stylesheet_contents = ''
stylesheet_contents = c.site.fetch_stylesheet_source()
c.allow_styles = True
pane = SubredditStylesheet(site=c.site,
stylesheet_contents=stylesheet_contents)
elif (location == 'stylesheet'
and c.site.can_view(c.user)
and not g.css_killswitch):
stylesheet = (c.site.stylesheet_contents_user or
c.site.stylesheet_contents)
stylesheet = c.site.fetch_stylesheet_source()
pane = SubredditStylesheetSource(stylesheet_contents=stylesheet)
elif (location == 'traffic' and
(c.site.public_traffic or
Expand Down
1 change: 0 additions & 1 deletion r2/r2/lib/app_globals.py
Expand Up @@ -218,7 +218,6 @@ class Globals(object):
'trust_local_proxies',
'shard_link_vote_queues',
'shard_commentstree_queues',
'subreddit_stylesheets_static',
'ENFORCE_RATELIMIT',
'RL_SITEWIDE_ENABLED',
'RL_OAUTH_SITEWIDE_ENABLED',
Expand Down
4 changes: 0 additions & 4 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -358,13 +358,9 @@ def get_subreddit_stylesheet_url(sr):
if c.secure:
if sr.stylesheet_url_https:
return sr.stylesheet_url_https
elif sr.stylesheet_contents_secure:
return sr.stylesheet_url
else:
if sr.stylesheet_url_http:
return sr.stylesheet_url_http
elif sr.stylesheet_contents:
return sr.stylesheet_url

def wiki_actions_menu(self, moderator=False):
buttons = []
Expand Down
52 changes: 5 additions & 47 deletions r2/r2/models/subreddit.py
Expand Up @@ -25,7 +25,6 @@
import base64
import collections
import datetime
import hashlib
import itertools
import json

Expand Down Expand Up @@ -113,7 +112,6 @@ class BaseSite(object):
_defaults = dict(
static_path=g.static_path,
stylesheet=None,
stylesheet_hash='',
header=None,
header_title='',
)
Expand Down Expand Up @@ -200,13 +198,6 @@ def get_modactions(cls, srs, mod=None, action=None):
def get_live_promos(self):
raise NotImplementedError

@property
def stylesheet_url(self):
from r2.lib.template_helpers import get_domain
return "//%s/stylesheet.css?v=%s" % (get_domain(cname=False,
subreddit=True),
self.stylesheet_hash)


class SubredditExists(Exception): pass

Expand All @@ -216,9 +207,6 @@ class Subreddit(Thing, Printable, BaseSite):
# attribute, even on a cname. So c.site.static_path should always be
# the same as g.static_path.
_defaults = dict(BaseSite._defaults,
stylesheet_contents='',
stylesheet_contents_secure='',
stylesheet_modified=None,
stylesheet_url_http="",
stylesheet_url_https="",
header_size=None,
Expand Down Expand Up @@ -434,12 +422,11 @@ def moderator_invites_with_perms(self):
(r._thing2_id, r.get_permissions())
for r in self.each_moderator_invite())

@property
def stylesheet_contents_user(self):
def fetch_stylesheet_source(self):
try:
return WikiPage.get(self, 'config/stylesheet')._get('content','')
except tdb_cassandra.NotFound:
return self._t.get('stylesheet_contents_user')
return ""

@property
def prev_stylesheet(self):
Expand Down Expand Up @@ -620,29 +607,12 @@ def change_css(self, content, parsed, prev=None, reason=None, author=None, force

minified_http, minified_https = parsed
if minified_http or minified_https:
if g.subreddit_stylesheets_static:
self.stylesheet_url_http = upload_stylesheet(minified_http)
self.stylesheet_url_https = g.media_provider.convert_to_https(
upload_stylesheet(minified_https))
self.stylesheet_hash = ""
self.stylesheet_contents = ""
self.stylesheet_contents_secure = ""
self.stylesheet_modified = None
else:
self.stylesheet_url_http = ""
self.stylesheet_url_https = ""
self.stylesheet_hash = hashlib.md5(minified_https).hexdigest()
self.stylesheet_contents = minified_http
self.stylesheet_contents_secure = minified_https
self.stylesheet_modified = datetime.datetime.now(g.tz)
self.stylesheet_url_http = upload_stylesheet(minified_http)
self.stylesheet_url_https = g.media_provider.convert_to_https(
upload_stylesheet(minified_https))
else:
self.stylesheet_url_http = ""
self.stylesheet_url_https = ""
self.stylesheet_contents = ""
self.stylesheet_contents_secure = ""
self.stylesheet_hash = ""
self.stylesheet_modified = datetime.datetime.now(g.tz)
self.stylesheet_contents_user = "" # reads from wiki; ensure pg clean
self._commit()

ModAction.create(self, c.user, action='wikirevise', details='Updated subreddit stylesheet')
Expand Down Expand Up @@ -1354,14 +1324,6 @@ def header_title(self):
def header_size(self):
return (self._base and self._base.header_size) or None

@property
def stylesheet_contents(self):
return self._base.stylesheet_contents if self._base else ""

@property
def stylesheet_contents_secure(self):
return self._base.stylesheet_contents_secure if self._base else ""

@property
def stylesheet_url_http(self):
return self._base.stylesheet_url_http if self._base else ""
Expand All @@ -1370,10 +1332,6 @@ def stylesheet_url_http(self):
def stylesheet_url_https(self):
return self._base.stylesheet_url_https if self._base else ""

@property
def stylesheet_hash(self):
return self._base.stylesheet_hash if self._base else ""

def get_all_comments(self):
from r2.lib.db.queries import get_sr_comments, merge_results
srs = Subreddit.user_subreddits(c.user, ids=False)
Expand Down

0 comments on commit 155342f

Please sign in to comment.