Install OSQA from git instead of svn
authorTom Hughes <tom@compton.nu>
Wed, 20 Aug 2014 13:06:17 +0000 (14:06 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 20 Aug 2014 13:09:06 +0000 (14:09 +0100)
cookbooks/osqa/attributes/default.rb
cookbooks/osqa/files/default/osmauth/__init__.py [deleted file]
cookbooks/osqa/files/default/osmauth/authentication.py [deleted file]
cookbooks/osqa/files/default/osmauth/forms.py [deleted file]
cookbooks/osqa/files/default/osmauth/osm.py [deleted file]
cookbooks/osqa/files/default/osmauth/templates/loginform.html [deleted file]
cookbooks/osqa/files/default/osmauth/urls.py [deleted file]
cookbooks/osqa/recipes/default.rb

index fb20a4d47f068b39d3648c68d35b7e2d95717c40..610f68605dbd1ef35da701605bedc919bf63d3c5 100644 (file)
@@ -1,4 +1,3 @@
-default[:osqa][:revision] = "1284"
 default[:osqa][:user] = "osqa"
 default[:osqa][:group] = nil
 default[:osqa][:database_name] = "osqa"
diff --git a/cookbooks/osqa/files/default/osmauth/__init__.py b/cookbooks/osqa/files/default/osmauth/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/cookbooks/osqa/files/default/osmauth/authentication.py b/cookbooks/osqa/files/default/osmauth/authentication.py
deleted file mode 100644 (file)
index 7c8e702..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateContext, InvalidAuthentication
-from forms import OpenStreetMapLoginForm
-
-class OpenStreetMapAuthConsumer(AuthenticationConsumer):
-    def process_authentication_request(self, request):
-        form_auth = OpenStreetMapLoginForm(request.POST)
-
-        if form_auth.is_valid():
-            request.session["auth_consumer_data"] = form_auth.get_user_data()
-            return form_auth.get_user()
-        else:
-            raise InvalidAuthentication(" ".join(form_auth.errors.values()[0]))
-
-    def get_user_data(self, key):
-        return {}
-
-class OpenStreetMapAuthContext(ConsumerTemplateContext):
-    mode = 'TOP_STACK_ITEM'
-    weight = 0
-    human_name = 'OpenStreetMap Login'
-    stack_item_template = 'modules/osmauth/loginform.html'
diff --git a/cookbooks/osqa/files/default/osmauth/forms.py b/cookbooks/osqa/files/default/osmauth/forms.py
deleted file mode 100644 (file)
index c59475e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-from osm import OpenStreetMapAPI
-from forum.forms import NextUrlField, UserNameField, SetPasswordForm
-from django.utils.translation import ugettext as _
-from django import forms
-
-class OpenStreetMapLoginForm(forms.Form):
-    """ osm account signin form """
-    next = NextUrlField()
-    username = UserNameField(required=False, skip_clean=True)
-    password = forms.CharField(max_length=128,
-                               widget=forms.widgets.PasswordInput(attrs={'class':'required login'}),
-                               required=False)
-
-    def __init__(self, data=None, files=None, auto_id='id_%s',
-                 prefix=None, initial=None):
-        super(OpenStreetMapLoginForm, self).__init__(data, files, auto_id,
-                                                     prefix, initial)
-        self.user_details = None
-
-    def _clean_nonempty_field(self, field):
-        value = None
-        if field in self.cleaned_data:
-            value = self.cleaned_data[field].strip()
-            if value == '':
-                value = None
-        self.cleaned_data[field] = value
-        return value
-
-    def clean_username(self):
-        return self._clean_nonempty_field('username')
-
-    def clean_password(self):
-        return self._clean_nonempty_field('password')
-
-    def clean(self):
-        error_list = []
-        username = self.cleaned_data['username']
-        password = self.cleaned_data['password']
-
-        self.user_details = None
-        if username and password:
-            api = OpenStreetMapAPI(username, password)
-
-            try:
-                self.user_details = api.user_details()
-            except:
-                del self.cleaned_data['username']
-                del self.cleaned_data['password']
-                error_list.insert(0, (_("Please enter valid username and password "
-                "(both are case-sensitive).")))
-                error_list.insert(0, _('Login failed.'))
-
-        elif password == None and username == None:
-            error_list.append(_('Please enter username and password'))
-        elif password == None:
-            error_list.append(_('Please enter your password'))
-        elif username == None:
-            error_list.append(_('Please enter user name'))
-        if len(error_list) > 0:
-            self._errors['__all__'] = forms.util.ErrorList(error_list)
-
-        return self.cleaned_data
-
-    def get_user(self):
-        """ get authenticated user """
-        return "http://www.openstreetmap.org/user/%s" % self.user_details["id"]
-
-    def get_user_data(self):
-        """ get user data for authenticated user """
-        return {
-            "username": self.user_details["display_name"]
-        }
diff --git a/cookbooks/osqa/files/default/osmauth/osm.py b/cookbooks/osqa/files/default/osmauth/osm.py
deleted file mode 100644 (file)
index 94dcd13..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-from xml.etree.ElementTree import ElementTree
-import urllib2
-
-class OpenStreetMapAPI:
-    def __init__(self, username, password):
-        passman = urllib2.HTTPPasswordMgr()
-        passman.add_password("Web Password", "https://api.openstreetmap.org/api/0.6", username, password)
-        authhandler =  urllib2.HTTPBasicAuthHandler(passman)
-        self.opener = urllib2.build_opener(authhandler)
-
-    def user_details(self):
-        response = self.opener.open("https://api.openstreetmap.org/api/0.6/user/details")
-        tree = ElementTree()
-        root = tree.parse(response)
-        user = root.find("user")
-        return {
-            "id": user.attrib["id"],
-            "display_name": user.attrib["display_name"]
-        }
diff --git a/cookbooks/osqa/files/default/osmauth/templates/loginform.html b/cookbooks/osqa/files/default/osmauth/templates/loginform.html
deleted file mode 100644 (file)
index 5091dfa..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-{% load i18n %}
-
-<fieldset id='openstreetmap_login_fs'>
-  <p><span class='big strong'>{% trans 'Enter your OpenStreetMap username and password' %}</span><br/><span class='grey'>({% trans 'or select your external provider below' %})</span></p>
-  <table>
-    <tr>
-        <td>
-             <label for="id_osm_username">{% trans 'Username' %}</label>
-        </td>
-        <td>
-             <input id="id_osm_username" type="text" class="required login" name="username" maxlength="255" />
-        </td>
-    </tr>
-    <tr>
-        <td>
-              <label for="id_osm_password">{% trans 'Password' %}</label>
-        </td>
-        <td>
-             <input id="id_osm_password" type="password" class="required login" name="password" maxlength="255" />
-        </td>
-    </tr>
-    <tr>
-        <td>
-            <input id="blogin" name="blogin" type="submit" value="{% trans 'Login' %}" />
-        </td>
-        <td>
-              <a href="https://www.openstreetmap.org/user/new">{% trans 'Create account' %}</a><span>&nbsp;|&nbsp;</span><a href="http://www.openstreetmap.org/user/forgot-password">{% trans 'Forgot your password?' %}</a>
-        </td>
-    </tr>
-  </table>
-</fieldset>
diff --git a/cookbooks/osqa/files/default/osmauth/urls.py b/cookbooks/osqa/files/default/osmauth/urls.py
deleted file mode 100644 (file)
index 62581f0..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-from django.conf.urls.defaults import *
-from django.views.generic.simple import direct_to_template
-from django.utils.translation import ugettext as _
-import views as app
-
-urlpatterns = patterns('',
-    url(r'^%s%s%s$' % (_('account/'), _('openstreetmap/'),  _('register/')), app.register, name='auth_openstreetmap_register'),
-)
index 98707f9ba1bd79c594c1061d0802782928a32aeb..d4ed159c89e6a1b93daaecd569e208a0f94866cf 100644 (file)
@@ -39,7 +39,7 @@ apache_module "wsgi"
 
 node[:osqa][:sites].each do |site|
   name = site[:name]
-  directory = site[:directory] || "/var/www/#{name}"
+  directory = site[:directory] || "/srv/#{name}"
   osqa_revision = site[:revision] || node[:osqa][:revision]
   site_user = site[:user] || node[:osqa][:user]
   site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
@@ -55,6 +55,12 @@ node[:osqa][:sites].each do |site|
     variables :user => site_user, :group => site_group
   end
 
+  directory directory do
+    owner site_user
+    group site_group
+    mode 0755
+  end
+
   execute "osqa-migrate" do
     action :nothing
     command "python manage.py migrate forum"
@@ -64,25 +70,15 @@ node[:osqa][:sites].each do |site|
     notifies :reload, "service[apache2]"
   end
 
-  subversion "#{directory}/osqa" do
+  git "#{directory}/osqa" do
     action :sync
-    repository "http://svn.osqa.net/svnroot/osqa/trunk"
-    revision osqa_revision
+    repository "git://git.openstreetmap.org/osqa.git"
+    revision "live"
     user site_user
     group site_group
     notifies :run, "execute[osqa-migrate]"
   end
 
-  remote_directory "#{directory}/osqa/forum_modules/osmauth" do
-    source "osmauth"
-    owner site_user
-    group site_group
-    mode 0755
-    files_owner site_user
-    files_group site_group
-    files_mode 0644
-  end
-
   template "#{directory}/osqa/osqa.wsgi" do
     source "osqa.wsgi.erb"
     owner site_user
@@ -97,6 +93,7 @@ node[:osqa][:sites].each do |site|
     line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
     line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
     line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
+    line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
     line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
     line.gsub!(/^APP_URL = 'http:\/\/'/, "APP_URL = 'http://#{name}'")
     line.gsub!(/^TIME_ZONE = 'America\/New_York'/, "TIME_ZONE = 'Europe/London'")