Skip to content

Commit

Permalink
Merge pull request #136 from qld-gov-au/QOLDEV-455-add-recaptcha
Browse files Browse the repository at this point in the history
QOLDEV-455 fix recaptcha failure message on CKAN 2.10
  • Loading branch information
ThrawnCA authored Aug 9, 2023
2 parents 5d7d749 + 10f0cfd commit 000caa1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
14 changes: 10 additions & 4 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,16 @@ commands:
ahoy title 'Run scenario tests'
ahoy cli "rm -f test/screenshots/*"
ahoy start-mailmock &
sleep 5 &&
ahoy cli "behave -k ${*:-test/features}" --tags=smoke $BEHAVE_TAGS && \
ahoy cli "behave -k ${*:-test/features} $BEHAVE_TAGS" || \
[ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
sleep 5
if [ "$BEHAVE_TAG" = "" ]; then
(ahoy cli "behave -k ${*:-test/features} --tags=smoke" \
&& ahoy cli "behave -k ${*:-test/features}"
) || [ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
else
# run tests with the specified tag
ahoy cli "behave -k ${*:-test/features} --tags=$BEHAVE_TAG" \
|| [ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
fi
ahoy stop-mailmock
start-mailmock:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ jobs:
run: bin/build.sh
timeout-minutes: 15

- name: Lint
run: ahoy lint
timeout-minutes: 10

- name: Unit test
run: bin/test.sh
run: ahoy test-unit
timeout-minutes: 10

- name: Scenario test
Expand Down
8 changes: 0 additions & 8 deletions bin/create-test-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ organisation_create=$( \
)
echo ${organisation_create}

echo "Updating organisation_admin to have admin privileges in the department-of-health Organisation:"
organisation_admin_update=$( \
curl -LsH "Authorization: ${API_KEY}" \
--data "id=department-of-health&username=organisation_admin&role=admin" \
${CKAN_ACTION_URL}/organization_member_create
)
echo ${organisation_admin_update}

echo "Creating non-organisation group:"
group_create=$( \
curl -LsH "Authorization: ${API_KEY}" \
Expand Down
31 changes: 11 additions & 20 deletions ckanext/qgov/common/views/user.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
# encoding: utf-8

from six import text_type as str

from flask import Blueprint

import ckan.lib.helpers as h
from ckan.plugins.toolkit import _, g, request, redirect_to, url_for
from ckan.views.user import login, me, EditView
from ckan.plugins.toolkit import g, redirect_to, url_for
import ckan.views.user
from ckan.views.user import _ as original_gettext, EditView

blueprint = Blueprint(u'user_overrides', __name__)


def logged_in_override():
"""
Override default CKAN behaviour to only redirect user to `came_from` URL if they are logged in.
Ref.: ckan/views/user.py > def logged_in()
:return:
"""
if g.user:
came_from = request.params.get(u'came_from', None)
return redirect_to(str(came_from)) if came_from and h.url_is_local(came_from) else me()
else:
h.flash_error(_(u'Login failed. Bad username or password or reCAPTCHA.'))
return login()


def user_edit_override():
"""
Override default CKAN behaviour of displaying "No user specified" message for /user/edit page and instead
Expand All @@ -39,8 +23,15 @@ def user_edit_override():
return EditView().dispatch_request()


blueprint.add_url_rule(u'/user/logged_in', u'logged_in', logged_in_override)
def _gettext_wrapper(key):
translation = original_gettext(key)
if key == 'Login failed. Bad username or password.':
translation = translation.replace('or password.', 'or password or reCAPTCHA.')
return translation


blueprint.add_url_rule(u'/user/edit', u'edit', user_edit_override)
ckan.views.user._ = _gettext_wrapper


def get_blueprints():
Expand Down
1 change: 1 addition & 0 deletions test/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,5 @@ def lock_account(context):
for x in range(11):
context.execute_steps(u"""
When I attempt to log in with password "incorrect password"
Then I should see "Bad username or password or reCAPTCHA."
""")

0 comments on commit 000caa1

Please sign in to comment.