Skip to content
This repository has been archived by the owner on Apr 12, 2018. It is now read-only.

Commit

Permalink
Added MPL headers, config options
Browse files Browse the repository at this point in the history
* Added ability to specify valid edit domains in config
* fixed the platform/version swap for /announcements
* fixed redirect to use /redirect and /redirect/{locale}
  • Loading branch information
jrconlin committed Oct 17, 2012
1 parent 1de443b commit f23a65b
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 12 deletions.
69 changes: 69 additions & 0 deletions README.rst
Expand Up @@ -4,3 +4,72 @@ CampainManager
Campaign Manager is a server that provides small HTML elements to be used
by the firefox browser as part of marketing and outreach.

Installing
----

System Requirements:
Please make sure the following packages are installed on the system:

gcc
virtualenv
sqlite

Once those packages are successfully installed:

$ make build

This will run the build steps required to get things started.
Please make sure that the build is successful and that all packages are installed.

$ cp campaign.ini campaign-local.ini
$ $EDITOR campaign-local.ini

(It is recommended that you copy campaign.ini to campaign-local.ini and
edit that file. This will prevent accidental updates of the configuration.)

You will need to change the line

[who:plugin:browserid]
audiences = Set.Domain.In.Ini.File

to be your current host address or machine name. This is used by Persona to
identify the correct recipient of the identity assertion. If this value does
not match your host, the assertion will fail.

Running
----

To run:

$ bin/pserve campaign-local.ini

This will start a server listening on the current host at port 8080. You
may change the port in use via the campaign-local.ini configuration file.

Authoring
----

https://$HOST:8080/author/

To create new announcements, you will need to connect via Persona with a
mozilla email address. If you wish to change this value, alter the
'auth.valid.domains' element in the campaign-local.ini configuration file.

Once connected, you will be presented with a form. Empty values are considered
"wild card" and will match all requests.

Requesting Announcements
----

https://$HOST:8080/announcements/$CHANNEL/$PLATFORM/$VERSION

An optional GET parameter of "idle" may be passed to indicate the number of
days the platform has been idle.

Redirection
---
https://$HOST:8080/redirect/$TOKEN
https://$HOST:8080/redirect/$LOCALE/$TOKEN

This will return a 302 to the correct destination for valid tokens, else 404

4 changes: 4 additions & 0 deletions __init__.py
@@ -1,3 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

def main(global_config, **settings):
print 'starting app...'
pass
9 changes: 9 additions & 0 deletions campaign.ini
Expand Up @@ -23,6 +23,15 @@ beaker.session.cache_dir = %(here)s/data
beaker.session.key = campaign
beaker.session.secret = Secret.

# please make sure to be as specific as possible when declaring these.
auth.valid.domains = ["@mozilla.com", "@mozilla.org"]

# redirection
# % ( HOST, PATH, ID)
#redir.url = http://%s/%s%s
#redir.host = localhost
# note, this is inserted into the redir.url pattern:
#redir.path = redirect/

[server:main]
use = egg:waitress#main
Expand Down
3 changes: 3 additions & 0 deletions campaign/__init__.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Main entry point
"""
from pyramid.config import Configurator
Expand Down
3 changes: 3 additions & 0 deletions campaign/auth/__init__.py
@@ -0,0 +1,3 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
3 changes: 3 additions & 0 deletions campaign/auth/browserid_auth.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import logging
import urllib2
import browserid
Expand Down
3 changes: 3 additions & 0 deletions campaign/auth/default.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from pyramid.security import authenticated_userid

class DefaultAuth(object):
Expand Down
4 changes: 4 additions & 0 deletions campaign/resources.py
@@ -1,3 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from pyramid.security import Everyone, Authenticated, Allow

class Root(object):
Expand Down
4 changes: 4 additions & 0 deletions campaign/storage/__init__.py
@@ -1,3 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

#import memcache
from dateutil import parser
from time import time
Expand Down
2 changes: 1 addition & 1 deletion campaign/storage/sql.py
Expand Up @@ -120,7 +120,7 @@ def get_announce(self, data):
'url':
settings.get('redir.url', 'http://%s/%s%s') % (
settings.get('redir.host', 'localhost'),
settings.get('redir.path', 'r/'),
settings.get('redir.path', 'redirect/'),
item.id)})
result.append(note)
return result
Expand Down
4 changes: 4 additions & 0 deletions campaign/templates/login.mako
@@ -1,5 +1,9 @@
<!DOCTYPE html>
<%
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
land = pageargs.get('landing', '/author/')
audience = pageargs.get('audience', 'localhost')
%>
Expand Down
3 changes: 3 additions & 0 deletions campaign/utils.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import string;

ALPHABET = (string.digits + string.letters)
Expand Down
33 changes: 22 additions & 11 deletions campaign/views.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" Cornice services.
"""
from campaign import LOG
Expand All @@ -12,7 +15,7 @@


fetch = Service(name='fetch',
path='/announcements/{channel}/{version}/{platform}',
path='/announcements/{channel}/{platform}/{version}',
description='Fetcher')
fetchall = Service(name="fetchall",
path='/announcements/',
Expand All @@ -30,7 +33,7 @@
path='/logout/',
description='logout')
redir = Service(name='redir',
path='/r/{token}',
path='/redirect/{token}',
description='redir')


Expand Down Expand Up @@ -113,19 +116,27 @@ def get_ideltime(request):
return {'idle_time': int(request.params.get('idle', 0))}


def authorized(email):
def authorized(request, email):
if email is None:
return False
settings = request.registry.settings
try:
for valid_domain in ['@mozilla.com', '@mozilla.org']:
if valid_domain in email:
domains = json.loads(settings.get('auth.valid.domains',
"['@mozilla.com', '@mozilla.org']"))
for valid_domain in domains:
if email.lower().endswith(valid_domain):
return True
except Exception,e:
except TypeError, e:
pass
except Exception, e:
import pdb; pdb.set_trace();
pass
return False


@fetchall.get()
def fetchall_snippets(request):
if not authorized(request.session.get('uid')):
if not authorized(request, request.session.get('uid')):
return login(request)
storage = request.registry.get('storage')
tdata = {"notes": storage.get_all_announce()}
Expand All @@ -135,7 +146,7 @@ def fetchall_snippets(request):
@author.get()
@authorx.get()
def admin_page(request, error=None):
if not authorized(request.session.get('uid')):
if not authorized(request, request.session.get('uid')):
return login(request)
tdata = fetchall_snippets(request)
tdata['author'] = request.session['uid']
Expand All @@ -151,7 +162,7 @@ def admin_page(request, error=None):
@author.post()
@authorx.post()
def manage_announce(request):
if not authorized(request.session.get('uid')):
if not authorized(request, request.session.get('uid')):
return login(request)
storage = request.registry.get('storage')
session = request.session
Expand Down Expand Up @@ -183,7 +194,7 @@ def manage_announce(request):

@author.delete()
def del_announce(request):
if not authorized(request.session.get('uid')):
if not authorized(request, request.session.get('uid')):
return login(request)
storage = request.registry.get('storage')
args = dict(request.params)
Expand Down Expand Up @@ -233,7 +244,7 @@ def login(request, skipAuth=False):
email = auth.get_user_id(request)
if email is None:
return login_page(request)
if authorized(email):
if authorized(request, email):
session = request.session
session['uid'] = email
session.persist()
Expand Down
3 changes: 3 additions & 0 deletions setup.py
@@ -1,3 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" Setup file.
"""
import os
Expand Down

0 comments on commit f23a65b

Please sign in to comment.