From 4181b42a26cdfdf5bda024fa28c00368dd5e2ab5 Mon Sep 17 00:00:00 2001 From: David Read Date: Thu, 22 Mar 2012 11:14:53 +0000 Subject: [PATCH 01/20] [master][noticket]: Fix - if db is not initialised and you are logged in then before this fix you get a 500 error, but now you get a nice 503 and message. --- ckan/controllers/home.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckan/controllers/home.py b/ckan/controllers/home.py index a675826af44..0024d442db2 100644 --- a/ckan/controllers/home.py +++ b/ckan/controllers/home.py @@ -14,8 +14,8 @@ class HomeController(BaseController): repo = model.repo def __before__(self, action, **env): - BaseController.__before__(self, action, **env) try: + BaseController.__before__(self, action, **env) context = {'model':model,'user': c.user or c.author} ckan.logic.check_access('site_read',context) except ckan.logic.NotAuthorized: From 10bb7f20a28caa429c0783100011d491fc3fed76 Mon Sep 17 00:00:00 2001 From: David Read Date: Mon, 30 Apr 2012 12:20:44 +0100 Subject: [PATCH 02/20] [release-v1.6.1][noticket] repoze.who handler paths are now read from who.ini so that they can be moved in the URI space. Added comments and logging. --- ckan/controllers/user.py | 13 ++++++++++--- ckan/lib/base.py | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py index 0a26d59c0f3..741cbea5d93 100644 --- a/ckan/controllers/user.py +++ b/ckan/controllers/user.py @@ -52,6 +52,11 @@ def _setup_template_variables(self, context): ## end hooks + def _get_repoze_handler(self, handler_name): + '''Returns the URL that repoze.who will respond to and perform a + login or logout.''' + return getattr(request.environ['repoze.who.plugins']['friendlyform'], handler_name) + def index(self): LIMIT = 20 @@ -165,7 +170,9 @@ def _save_new(self, context): return self.new(data_dict, errors, error_summary) if not c.user: # Redirect to a URL picked up by repoze.who which performs the login - h.redirect_to('/login_generic?login=%s&password=%s' % ( + login_url = self._get_repoze_handler('login_handler_path') + h.redirect_to('%s?login=%s&password=%s' % ( + login_url, str(data_dict['name']), quote(data_dict['password1'].encode('utf-8')))) else: @@ -283,10 +290,10 @@ def logged_in(self): h.redirect_to(locale=lang, controller='user', action='login') def logout(self): - # save our language in the session so we don't loose it + # save our language in the session so we don't lose it session['lang'] = request.environ.get('CKAN_LANG') session.save() - h.redirect_to('/user/logout') + h.redirect_to(self._get_repoze_handler('logout_handler_path')) def set_lang(self, lang): # this allows us to set the lang in session. Used for logging diff --git a/ckan/lib/base.py b/ckan/lib/base.py index 0dfe78e41f1..3d46b45ece0 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -142,9 +142,11 @@ def _identify_user(self): b) For API calls he may set a header with his API key. If the user is identified then: c.user = user name (unicode) + c.userobj = user object c.author = user name otherwise: c.user = None + c.userobj = None c.author = user\'s IP address (unicode) ''' # see if it was proxied first @@ -153,8 +155,10 @@ def _identify_user(self): c.remote_addr = request.environ.get('REMOTE_ADDR', 'Unknown IP Address') # environ['REMOTE_USER'] is set by repoze.who if it authenticates a user's - # cookie or OpenID. (But it doesn't check the user (still) exists in our - # database - we need to do that here. + # cookie or OpenID. But repoze.who doesn't check the user (still) + # exists in our database - we need to do that here. (Another way would + # be with an userid_checker, but that would mean another db access. + # See: http://docs.repoze.org/who/1.0/narr.html#module-repoze.who.plugins.sql ) c.user = request.environ.get('REMOTE_USER', '') if c.user: c.user = c.user.decode('utf8') @@ -204,9 +208,12 @@ def __call__(self, environ, start_response): if not is_valid_cookie_data: if session.id: if not session.get('lang'): + self.log.debug('No session data any more - deleting session') + self.log.debug('Session: %r', session.items()) session.delete() else: response.delete_cookie(cookie) + self.log.debug('No session data any more - deleting session cookie') # Remove auth_tkt repoze.who cookie if user not logged in. elif cookie == 'auth_tkt' and not session.id: response.delete_cookie(cookie) From 5c72aa3d2485ca7fc96f27c567d455c431401b95 Mon Sep 17 00:00:00 2001 From: David Read Date: Mon, 30 Apr 2012 12:57:08 +0100 Subject: [PATCH 03/20] Addition to who change (last commit). --- ckan/controllers/user.py | 1 + ckan/templates/user/login.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py index 741cbea5d93..b789eb23a16 100644 --- a/ckan/controllers/user.py +++ b/ckan/controllers/user.py @@ -264,6 +264,7 @@ def login(self): g.openid_enabled = False if not c.user: + c.login_handler = h.url_for(self._get_repoze_handler('login_handler_path')) return render('user/login.html') else: return render('user/logout_first.html') diff --git a/ckan/templates/user/login.html b/ckan/templates/user/login.html index 9d4c365473e..1b2e86bf481 100644 --- a/ckan/templates/user/login.html +++ b/ckan/templates/user/login.html @@ -22,7 +22,7 @@
-
+
From 289a36784403ee6bb23c656bb415770ef52b38d5 Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Mon, 30 Apr 2012 13:45:21 +0100 Subject: [PATCH 04/20] Add additional bold variant of the Ubuntu font family This allows us to have bold headers at smaller font sizes. --- ckan/templates/layout_base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckan/templates/layout_base.html b/ckan/templates/layout_base.html index a983d4bc606..7a8cb9b51a6 100644 --- a/ckan/templates/layout_base.html +++ b/ckan/templates/layout_base.html @@ -27,7 +27,7 @@ - + From 762906da1ba23408b0dd16c5420b8cb27e53cc0a Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Mon, 30 Apr 2012 14:16:24 +0100 Subject: [PATCH 05/20] Refactor related delete button Removed the inline click handlers and moved the JavaScript into application.js. Also remove the item with JavaScript rather than reload the page. --- ckan/public/scripts/application.js | 41 ++++++++++++++++-------- ckan/templates/_util.html | 6 ++-- ckan/templates/package/related_list.html | 19 ----------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js index 0d3628ebf76..5614ada8f69 100644 --- a/ckan/public/scripts/application.js +++ b/ckan/public/scripts/application.js @@ -1145,8 +1145,22 @@ CKAN.Utils = function($, my) { $('
').html(msg).hide().prependTo(form).fadeIn(); } + function relatedRequest(action, method, data) { + return $.ajax({ + type: method, + dataType: 'json', + contentType: 'application/json', + url: CKAN.SITE_URL + '/api/3/action/related_' + action, + data: data ? JSON.stringify(data) : undefined, + error: function(err, txt, w) { + // This needs to be far more informative. + addAlert('Error: Unable to ' + action + ' related item'); + } + }); + } + // Center thumbnails vertically. - $('.related-items').each(function () { + var relatedItems = $('.related-items').each(function () { var item = $(this); function vertiallyAlign() { @@ -1164,6 +1178,15 @@ CKAN.Utils = function($, my) { item.find('.description').truncate(); }); + // Add a handler for the delete buttons. + relatedItems.on('click', '[data-action=delete]', function (event) { + var id = $(this).data('relatedId'); + relatedRequest('delete', 'POST', {id: id}).done(function () { + $('#related-item-' + id).remove(); + }); + event.preventDefault(); + }); + $(form).submit(function (event) { event.preventDefault(); @@ -1186,18 +1209,10 @@ CKAN.Utils = function($, my) { return; } - $.ajax({ - type: this.method, - url: CKAN.SITE_URL + '/api/3/action/related_create', - data: JSON.stringify(data), - success: function (data) { - window.location.reload(); - }, - error: function(err, txt, w) { - // This needs to be far more informative. - addAlert('Error: Unable to add related item'); - } - }); + relatedRequest('create', this.method, data).done(function () { + // TODO: Insert item dynamically. + window.location.reload(); + }); }); }; diff --git a/ckan/templates/_util.html b/ckan/templates/_util.html index 5aa7c077c7e..8c2991877fd 100644 --- a/ckan/templates/_util.html +++ b/ckan/templates/_util.html @@ -126,16 +126,16 @@ -
  • +