auth-tokens: remove showing builtin tokens

This commit is contained in:
Marcin Kuzminski 2017-02-27 12:04:43 +01:00
parent bcd1b3ff15
commit 10ce5d446b
8 changed files with 7 additions and 118 deletions

View file

@ -408,17 +408,10 @@ class MyAccountController(BaseController):
@auth.CSRFRequired()
def my_account_auth_tokens_delete(self):
auth_token = request.POST.get('del_auth_token')
user_id = c.rhodecode_user.user_id
if request.POST.get('del_auth_token_builtin'):
user = User.get(user_id)
if user:
user.api_key = generate_auth_token(user.username)
Session().add(user)
Session().commit()
h.flash(_("Auth token successfully reset"), category='success')
elif auth_token:
AuthTokenModel().delete(auth_token, c.rhodecode_user.user_id)
del_auth_token = request.POST.get('del_auth_token')
if del_auth_token:
AuthTokenModel().delete(del_auth_token, c.rhodecode_user.user_id)
Session().commit()
h.flash(_("Auth token successfully deleted"), category='success')

View file

@ -507,16 +507,9 @@ class UsersController(BaseController):
h.flash(_("You can't edit this user"), category='warning')
return redirect(url('users'))
auth_token = request.POST.get('del_auth_token')
if request.POST.get('del_auth_token_builtin'):
user = User.get(c.user.user_id)
if user:
user.api_key = generate_auth_token(user.username)
Session().add(user)
Session().commit()
h.flash(_("Auth token successfully reset"), category='success')
elif auth_token:
AuthTokenModel().delete(auth_token, c.user.user_id)
del_auth_token = request.POST.get('del_auth_token')
if del_auth_token:
AuthTokenModel().delete(del_auth_token, c.user.user_id)
Session().commit()
h.flash(_("Auth token successfully deleted"), category='success')

View file

@ -648,13 +648,6 @@ class User(Base, BaseModel):
return False
@property
def builtin_token_roles(self):
roles = [
UserApiKeys.ROLE_API, UserApiKeys.ROLE_FEED, UserApiKeys.ROLE_HTTP
]
return map(UserApiKeys._get_role_name, roles)
@property
def ip_addresses(self):
ret = UserIpMap.query().filter(UserIpMap.user == self).all()

View file

@ -643,13 +643,6 @@ class User(Base, BaseModel):
return False
@property
def builtin_token_roles(self):
roles = [
UserApiKeys.ROLE_API, UserApiKeys.ROLE_FEED, UserApiKeys.ROLE_HTTP
]
return map(UserApiKeys._get_role_name, roles)
@property
def ip_addresses(self):
ret = UserIpMap.query().filter(UserIpMap.user == self).all()

View file

@ -4,35 +4,9 @@
</div>
<div class="panel-body">
<p>
${_('Built-in tokens can be used to authenticate with all possible options.')}<br/>
${_('Each token can have a role. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations.')}
</p>
<table class="rctable auth_tokens">
<tr>
<td class="truncate-wrap td-authtoken"><div class="user_auth_tokens truncate autoexpand"><code>${c.user.api_key}</code></div></td>
<td class="td-tags">
<span class="tag disabled">${_('Built-in')}</span>
</td>
<td class="td-tags">
% for token in c.user.builtin_token_roles:
<span class="tag disabled">
${token}
</span>
% endfor
</td>
<td class="td-exp">${_('expires')}: ${_('never')}</td>
<td class="td-action">
${h.secure_form(url('my_account_auth_tokens'),method='delete')}
${h.hidden('del_auth_token',c.user.api_key)}
${h.hidden('del_auth_token_builtin',1)}
<button class="btn-link btn-danger" type="submit"
onclick="return confirm('${_('Confirm to reset this auth token: %s') % c.user.api_key}');">
<i class="icon-refresh"></i>
${_('Reset')}
</button>
${h.end_form()}
</td>
</tr>
%if c.user_auth_tokens:
%for auth_token in c.user_auth_tokens:
<tr class="${'expired' if auth_token.expired else ''}">

View file

@ -5,30 +5,6 @@
<div class="panel-body">
<div class="apikeys_wrap">
<table class="rctable auth_tokens">
<tr>
<td class="truncate-wrap td-authtoken"><div class="user_auth_tokens truncate autoexpand"><code>${c.user.api_key}</code></div></td>
<td class="td-tags">
<span class="tag disabled">${_('Built-in')}</span>
</td>
<td class="td-tags">
% for token in c.user.builtin_token_roles:
<span class="tag disabled">
${token}
</span>
% endfor
</td>
<td class="td-exp">${_('expires')}: ${_('never')}</td>
<td class="td-action">
${h.secure_form(url('edit_user_auth_tokens', user_id=c.user.user_id),method='delete')}
${h.hidden('del_auth_token',c.user.api_key)}
${h.hidden('del_auth_token_builtin',1)}
<button class="btn btn-link btn-danger" type="submit"
onclick="return confirm('${_('Confirm to reset this auth token: %s') % c.user.api_key}');">
${_('Reset')}
</button>
${h.end_form()}
</td>
</tr>
%if c.user_auth_tokens:
%for auth_token in c.user_auth_tokens:
<tr class="${'expired' if auth_token.expired else ''}">

View file

@ -312,22 +312,6 @@ class TestMyAccountController(TestController):
keys = user.extra_auth_tokens
assert 1 == len(keys)
def test_my_account_reset_main_auth_token(self):
usr = self.log_user('test_regular2', 'test12')
user = User.get(usr['user_id'])
api_key = user.api_key
response = self.app.get(url('my_account_auth_tokens'))
response.mustcontain(api_key)
response.mustcontain('expires: never')
response = self.app.post(
url('my_account_auth_tokens'),
{'_method': 'delete', 'del_auth_token_builtin': api_key,
'csrf_token': self.csrf_token})
assert_session_flash(response, 'Auth token successfully reset')
response = response.follow()
response.mustcontain(no=[api_key])
def test_valid_change_password(self, user_util):
new_password = 'my_new_valid_password'
user = user_util.create_user(password=self.test_user_1_password)

View file

@ -625,20 +625,3 @@ class TestAdminUsersController(TestController):
assert_session_flash(response, 'Auth token successfully deleted')
keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
assert 0 == len(keys)
def test_reset_main_auth_token(self):
self.log_user()
user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
user_id = user.user_id
api_key = user.api_key
response = self.app.get(url('edit_user_auth_tokens', user_id=user_id))
response.mustcontain(api_key)
response.mustcontain('expires: never')
response = self.app.post(
url('edit_user_auth_tokens', user_id=user_id),
{'_method': 'delete', 'del_auth_token_builtin': api_key,
'csrf_token': self.csrf_token})
assert_session_flash(response, 'Auth token successfully reset')
response = response.follow()
response.mustcontain(no=[api_key])