Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions doajtest/testbook/user_management/user_management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ tests:
- You are taken to the new user form
- The "api" role and "publisher" role are pre-filled in the Roles field.
- The ID box is prefilled with an alphanumeric value
- There are no user attributes options available in the form
- step: Click in the "Roles" field
results:
- A pull-down menu appears with all the allowed roles
- step: Click in the 'ID' field
results:
- It is editable
- Change the ID to something memorable
- step: Enter test values into each field in the form
- step: Click "Create User"
- step: Enter test values into each remaining field in the form
- step: Click "Register"
results:
- You are taken back to the /account
- You see a message Debug mode - url for verify is /account/reset/f1b6b123b5f34cd0aa81807a90a096f2
- /account/reset/f1b6b123b5f34cd0aa81807a90a096f2 is a link and is clickable DO
NOT CLICK IT YET
- 'You see a message '' Account created for dom+test5@doaj.org. View Account:
- You see a message like "Debug mode - url for verify is ..."
- The verify URL in the message is a link and is clickable DO NOT CLICK IT YET
- 'You see a message '' Account created for [some email address]. View Account:
/account/testingID'''
- /account/testingID is a link and is clickable DO NOT CLICK IT YET
- The ID (/testerID in the example above) matches the ID you chose on line 11
Expand Down Expand Up @@ -145,9 +145,26 @@ tests:
- Your account page is shown
- Your ID and email address are displayed
- You can see your user roles but you cannot edit them
- You do not have any user attribute fields available to you
- include:
fragment: edit_account


- title: Edit your own user account (editor / associate editor)
context:
role: editor
setup:
- create an editor account with some attributes set
steps:
- step: Log in to your editor account
- step: Go to Settings under My Account
results:
- Your account page is shown
- Your ID and email address are displayed
- You can see your user roles but you cannot edit them
- You can see your user attributes but you cannot edit them
- include:
fragment: edit_account

- title: Edit your own user account (admin)
context:
role: admin
Expand All @@ -157,6 +174,12 @@ tests:
results:
- Your account page is shown
- Your ID and email address are displayed
- You can see your user roles and you can edit them
- You can see your user attributes and you can edit them
- step: Add one or more workflow attributes
- step: Add one or more language attributes
- step: Add one or more country attributes
- step: Add one or more free text tag attributes
- include:
fragment: edit_account
- step: Log back in to your admin account and go to Settings
Expand All @@ -180,6 +203,10 @@ tests:
- The user's account page is displayed
- A warning alerts you 'NOTE you are editing a user account that is not your own.
Be careful!'
- step: Add one or more workflow attributes
- step: Add one or more language attributes
- step: Add one or more country attributes
- step: Add one or more free text tag attributes
- include:
fragment: edit_account
- include:
Expand All @@ -192,6 +219,7 @@ tests:
- step: Put the username of the account you deleted into the search box
results:
- There are no results to display

- title: User account with journals/applications
context:
role: admin
Expand Down
56 changes: 55 additions & 1 deletion doajtest/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,15 @@ def test_08_iterate(self):
def test_09_account(self):
# Make a new account
acc = models.Account.make_account(email='user@example.com', username='mrs_user',
roles=['api', 'associate_editor'])
roles=['api', 'associate_editor'],
attributes={constants.USER_ATTR__WORKFLOW: ["triage"]})

# Check the new user has the right roles
assert acc.has_role('api')
assert acc.has_role('associate_editor')
assert not acc.has_role('admin')
assert acc.marketing_consent is None
assert acc.has_attribute(constants.USER_ATTR__WORKFLOW, "triage")

# check the api key has been generated
assert acc.api_key is not None
Expand Down Expand Up @@ -624,6 +626,58 @@ def test_09_account(self):
acc2.save()
assert acc2.api_key is not None

def test_09a_account_attributes(self):
acc = models.Account.make_account(email='user@example.com', username='mrs_user',
roles=['api', 'associate_editor'],
attributes={constants.USER_ATTR__WORKFLOW: ["triage"]})
assert acc.has_attribute(constants.USER_ATTR__WORKFLOW, "triage")

acc.add_attribute(constants.USER_ATTR__WORKFLOW, "quality")
acc.add_attribute(constants.USER_ATTR__LANGUAGE, "FR")
acc.add_attribute(constants.USER_ATTR__LANGUAGE, "EN")
acc.add_attribute(constants.USER_ATTR__COUNTRY, "DE")
acc.add_attribute(constants.USER_ATTR__COUNTRY, "ES")
acc.add_attribute(constants.USER_ATTR__TAG, "test")

raw = acc.attributes
assert raw.get(constants.USER_ATTR__WORKFLOW) == ["triage", "quality"]
assert raw.get(constants.USER_ATTR__LANGUAGE) == ["FR", "EN"]
assert raw.get(constants.USER_ATTR__COUNTRY) == ["DE", "ES"]
assert raw.get(constants.USER_ATTR__TAG) == ["test"]

assert acc.attribute_workflow == ["triage", "quality"]
assert acc.attribute_language == ["FR", "EN"]
assert acc.attribute_country == ["DE", "ES"]
assert acc.attribute_tag == ["test"]

assert acc.has_attribute(constants.USER_ATTR__WORKFLOW, "triage")
assert acc.has_attribute(constants.USER_ATTR__WORKFLOW, "quality")
assert acc.has_attribute(constants.USER_ATTR__LANGUAGE, "FR")
assert acc.has_attribute(constants.USER_ATTR__LANGUAGE, "EN")
assert acc.has_attribute(constants.USER_ATTR__COUNTRY, "DE")
assert acc.has_attribute(constants.USER_ATTR__COUNTRY, "ES")
assert acc.has_attribute(constants.USER_ATTR__TAG, "test")

assert acc.get_attributes(constants.USER_ATTR__WORKFLOW) == ["triage", "quality"]
assert acc.get_attributes(constants.USER_ATTR__LANGUAGE) == ["FR", "EN"]
assert acc.get_attributes(constants.USER_ATTR__COUNTRY) == ["DE", "ES"]
assert acc.get_attributes(constants.USER_ATTR__TAG) == ["test"]

del acc.attributes
raw = acc.attributes
assert raw is None

# try some error cases
with self.assertRaises(ValueError):
acc.add_attribute("whatever", "something")

with self.assertRaises(ValueError):
acc.has_attribute("whatever", "something")

with self.assertRaises(ValueError):
acc.get_attributes("whatever")


def test_10_block(self):
a = models.Article()
a.save()
Expand Down
21 changes: 21 additions & 0 deletions portality/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@
# TODO add ultra_bulk_delete and refactor view to use constants
ROLE_ADMIN_REPORT_WITH_NOTES = "ultra_admin_reports_with_notes" # MUST start with ultra_ so that superusers don't gain

USER_ATTR__WORKFLOW = "workflow"
USER_ATTR__LANGUAGE = "language"
USER_ATTR__COUNTRY = "country"
USER_ATTR__TAG = "tag"

USER_ATTR__ALL = [
USER_ATTR__WORKFLOW,
USER_ATTR__LANGUAGE,
USER_ATTR__COUNTRY,
USER_ATTR__TAG
]

EWF__TRIAGE = "Triage"
EWF__QUICK_FAIL = "Quick Fail"
EWF__QUALITY_REVIEW = "Quality Review"

EWF__ALL_STAGES = [
EWF__TRIAGE,
EWF__QUICK_FAIL,
EWF__QUALITY_REVIEW
]

CRON_NEVER = {"month": "2", "day": "31", "day_of_week": "*", "hour": "*", "minute": "*"}

Expand Down
20 changes: 14 additions & 6 deletions portality/forms/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,13 @@ def __init__(self, message=None):

def __call__(self, form, field):
if field.data is not None and field.data != '':
check = get_currency_code(field.data, fail_if_not_found=True)
if check is None:
raise validators.ValidationError(self.message)
value = field.data
if not isinstance(value, list):
value = [value]
for v in value:
check = get_currency_code(v, fail_if_not_found=True)
if check is None:
raise validators.ValidationError(self.message)


class CurrentISOLanguage(object):
Expand All @@ -683,6 +687,10 @@ def __init__(self, message=None):

def __call__(self, form, field):
if field.data is not None and field.data != '':
check = isolang.find(field.data)
if check is None:
raise validators.ValidationError(self.message)
value = field.data
if not isinstance(value, list):
value = [value]
for v in value:
check = isolang.find(v)
if check is None:
raise validators.ValidationError(self.message)
Empty file.
Loading
Loading