Browse files

Publish fedmsg messages for awarded frontend badges. For #136.

  • Loading branch information...
1 parent 91e6e5b commit b49b164f531a75d3e1d837a3dd56a216cf90c4c1 @ralphbean ralphbean committed Aug 2, 2013
Showing with 77 additions and 1 deletion.
  1. +1 −0 development.ini
  2. +30 −0 fedmsg.d/fedmsg-config.py
  3. +46 −1 tahrir/views.py
View
1 development.ini
@@ -40,6 +40,7 @@ tahrir.openid_identifier = https://id.fedoraproject.org/
tahrir.openid_realm = https://localhost:8000
tahrir.secure_cookies = False
tahrir.allow_changenick = True
+tahrir.use_fedmsg = True
# TODO -- set this to prod for production.
tahrir.websocket.topic = org.fedoraproject.stg.fedbadges.badge.award
View
30 fedmsg.d/fedmsg-config.py
@@ -0,0 +1,30 @@
+""" This is just an example fedmsg config file to be used
+during development of tahrir.
+"""
+
+import socket
+hostname = socket.gethostname()
+
+config = dict(
+ endpoints={
+ "relay_outbound": ["tcp://127.0.0.1:4001"],
+ "tahrir.%s" % hostname: [
+ "tcp://127.0.0.1:5001",
+ "tcp://127.0.0.1:5002",
+ "tcp://127.0.0.1:5003",
+ "tcp://127.0.0.1:5004",
+ ],
+ },
+
+ relay_inbound="tcp://127.0.0.1:2003",
+ environment="dev",
+ high_water_mark=0,
+ io_threads=1,
+ post_init_sleep=0.2,
+ irc=[],
+ zmq_enabled=True,
+ zmq_strict=False,
+
+ sign_messages=False,
+ validate_messages=False,
+)
View
47 tahrir/views.py
@@ -39,9 +39,19 @@
from moksha.wsgi.widgets.api import get_moksha_socket, LiveWidget
+# Optional. Emit messages to the fedmsg bus.
+fedmsg = None
+try:
+ import fedmsg
+except ImportError:
+ pass
+
@view_config(route_name='admin', renderer='admin.mak', permission='admin')
def admin(request):
+
+ settings = request.registry.settings
+
# TODO: Check if I even need this anymore... leaving for now.
request.session['came_from'] = request.route_url('admin')
@@ -113,6 +123,25 @@ def admin(request):
request.POST.get('assertion-person-email'),
issued_on)
+ if fedmsg and settings.get('tahrir.use_fedmsg', False):
+ person = request.db.get_person(
+ person_email=request.POST.get('assertion-person-email'))
+ badge = request.db.get_badge(
+ badge_id=request.POST.get('assertion-badge-id'))
+ fedmsg.publish(
+ modname="fedbadges", topic="badge.award",
+ msg=dict(
+ badge=dict(
+ name=badge.name,
+ description=badge.description,
+ image_url=badge.image,
+ ),
+ user=dict(
+ username=person.nickname,
+ badges_user_id=person.id
+ ),
+ ))
+
return dict(
auth_principals=effective_principals(request),
awarded_assertions=awarded_assertions,
@@ -198,6 +227,8 @@ def action(context, request):
def invitation_claim(request):
""" Action that awards a person a badge after scanning a qrcode. """
+ settings = request.registry.settings
+
if request.context.expires_on < datetime.now():
return HTTPGone("That invitation is expired.")
@@ -217,9 +248,23 @@ def invitation_claim(request):
person.email,
datetime.now())
+ if fedmsg and settings.get('tahrir.use_fedmsg', False):
+ fedmsg.publish(
+ modname="fedbadges", topic="badge.award",
+ msg=dict(
+ badge=dict(
+ name=badge.name,
+ description=badge.description,
+ image_url=badge.image,
+ ),
+ user=dict(
+ username=person.nickname,
+ badges_user_id=person.id
+ ),
+ ))
+
# TODO -- return them to a page that auto-exports their badges.
# TODO -- flash and tell them they got the badge
- # TODO -- emit a fedmsg message showing they got the badge
return HTTPFound(location=request.route_url('home'))

0 comments on commit b49b164

Please sign in to comment.