Skip to content

Commit

Permalink
[#3027] redirect to user feed after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nut committed Jun 2, 2016
1 parent 7b6dbed commit a75630d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
12 changes: 10 additions & 2 deletions ckan/controllers/user.py
Expand Up @@ -166,7 +166,8 @@ def new(self, data=None, errors=None, error_summary=None):
'''GET to display a form for registering a new user.
or POST the form data to actually do the user registration.
'''
context = {'model': model, 'session': model.Session,
context = {'model': model,
'session': model.Session,
'user': c.user,
'auth_user_obj': c.userobj,
'schema': self._new_form_to_db_schema(),
Expand Down Expand Up @@ -264,7 +265,14 @@ def _save_new(self, context):
h.flash_success(_('User "%s" is now registered but you are still '
'logged in as "%s" from before') %
(data_dict['name'], c.user))
return render('user/logout_first.html')
if authz.is_sysadmin(c.user):
# the sysadmin created a new user. We redirect him to the
# activity page for the newly created user
h.redirect_to(controller='user',
action='activity',
id=data_dict['name'])
else:
return render('user/logout_first.html')

def edit(self, id=None, data=None, errors=None, error_summary=None):
context = {'save': 'save' in request.params,
Expand Down
41 changes: 31 additions & 10 deletions ckan/tests/controllers/test_user.py
Expand Up @@ -59,6 +59,37 @@ def test_register_user_bad_password(self):
response = form.submit('save')
assert_true('The passwords you entered do not match' in response)

def test_create_user_as_sysadmin(self):
admin_pass = 'pass'
sysadmin = factories.Sysadmin(password=admin_pass)
app = self._get_test_app()

# Have to do an actual login as this test relies on repoze
# cookie handling.

# get the form
response = app.get('/user/login')
# ...it's the second one
login_form = response.forms[1]
# fill it in
login_form['login'] = sysadmin['name']
login_form['password'] = admin_pass
# submit it
login_form.submit('save')

response = app.get(
url=url_for(controller='user', action='register'),
)
assert "user-register-form" in response.forms
form = response.forms['user-register-form']
form['name'] = 'newestuser'
form['fullname'] = 'Newest User'
form['email'] = 'test@test.com'
form['password1'] = 'testpassword'
form['password2'] = 'testpassword'
response2 = form.submit('save')
assert '/user/activity' in response2.location


class TestLoginView(helpers.FunctionalTestBase):
def test_registered_user_login(self):
Expand Down Expand Up @@ -224,16 +255,6 @@ def test_user_edit_not_logged_in(self):
status=403
)

def test_create_user_as_sysadmin(self):
sysadmin = factories.Sysadmin()
app = self._get_test_app()
env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
response = app.get(
url=url_for(controller='user', action='register'),
extra_environ=env,
)
assert "user-register-form" in response.forms

def test_edit_user(self):
user = factories.User(password='pass')
app = self._get_test_app()
Expand Down

0 comments on commit a75630d

Please sign in to comment.