user_edit_auth_tokens.mako
196 lines
| 7.2 KiB
| application/x-mako
|
MakoHtmlLexer
r4232 | <%namespace name="base" file="/base/base.mako"/> | |||
r1282 | <div class="panel panel-default"> | |||
<div class="panel-heading"> | ||||
r4232 | <h3 class="panel-title"> | |||
${base.gravatar_with_user(c.user.username, 16, tooltip=False, _class='pull-left')} | ||||
- ${_('Authentication Tokens')} | ||||
</h3> | ||||
r1282 | </div> | |||
<div class="panel-body"> | ||||
<div class="apikeys_wrap"> | ||||
r1480 | <p> | |||
r3391 | ${_('Authentication tokens can be used to interact with the API, or VCS-over-http. ' | |||
'Each token can have a role. Token with a role can be used only in given context, ' | ||||
r1480 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} | |||
</p> | ||||
r1282 | <table class="rctable auth_tokens"> | |||
r1480 | <tr> | |||
<th>${_('Token')}</th> | ||||
<th>${_('Description')}</th> | ||||
<th>${_('Role')}</th> | ||||
r3391 | <th>${_('Repository Scope')}</th> | |||
r1480 | <th>${_('Expiration')}</th> | |||
<th>${_('Action')}</th> | ||||
</tr> | ||||
r1282 | %if c.user_auth_tokens: | |||
%for auth_token in c.user_auth_tokens: | ||||
r3391 | <tr class="${('expired' if auth_token.expired else '')}"> | |||
<td class="truncate-wrap td-authtoken"> | ||||
<div class="user_auth_tokens truncate autoexpand"> | ||||
<code>${auth_token.api_key}</code> | ||||
</div> | ||||
</td> | ||||
r1282 | <td class="td-wrap">${auth_token.description}</td> | |||
<td class="td-tags"> | ||||
r1518 | <span class="tag disabled">${auth_token.role_humanized}</span> | |||
r1282 | </td> | |||
r3391 | <td class="td">${auth_token.scope_humanized}</td> | |||
r1282 | <td class="td-exp"> | |||
%if auth_token.expires == -1: | ||||
r1480 | ${_('never')} | |||
r1282 | %else: | |||
%if auth_token.expired: | ||||
r1480 | <span style="text-decoration: line-through">${h.age_component(h.time_to_utcdatetime(auth_token.expires))}</span> | |||
r1282 | %else: | |||
r1480 | ${h.age_component(h.time_to_utcdatetime(auth_token.expires))} | |||
r1282 | %endif | |||
%endif | ||||
</td> | ||||
r1518 | <td class="td-action"> | |||
r2105 | ${h.secure_form(h.route_path('edit_user_auth_tokens_delete', user_id=c.user.user_id), request=request)} | |||
r1821 | ${h.hidden('del_auth_token', auth_token.user_api_key_id)} | |||
r1282 | <button class="btn btn-link btn-danger" type="submit" | |||
r1821 | onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');"> | |||
r1282 | ${_('Delete')} | |||
</button> | ||||
${h.end_form()} | ||||
</td> | ||||
</tr> | ||||
%endfor | ||||
%else: | ||||
<tr><td><div class="ip">${_('No additional auth tokens specified')}</div></td></tr> | ||||
%endif | ||||
</table> | ||||
</div> | ||||
<div class="user_auth_tokens"> | ||||
r2105 | ${h.secure_form(h.route_path('edit_user_auth_tokens_add', user_id=c.user.user_id), request=request)} | |||
r1282 | <div class="form form-vertical"> | |||
<!-- fields --> | ||||
<div class="fields"> | ||||
<div class="field"> | ||||
<div class="label"> | ||||
r1480 | <label for="new_email">${_('New authentication token')}:</label> | |||
r1282 | </div> | |||
<div class="input"> | ||||
${h.text('description', class_='medium', placeholder=_('Description'))} | ||||
r2083 | ${h.hidden('lifetime')} | |||
r1282 | ${h.select('role', '', c.role_options)} | |||
r1518 | ||||
% if c.allow_scoped_tokens: | ||||
${h.hidden('scope_repo_id')} | ||||
% else: | ||||
${h.select('scope_repo_id_disabled', '', ['Scopes available in EE edition'], disabled='disabled')} | ||||
% endif | ||||
r1282 | </div> | |||
r1518 | <p class="help-block"> | |||
${_('Repository scope works only with tokens with VCS type.')} | ||||
</p> | ||||
r1282 | </div> | |||
<div class="buttons"> | ||||
r1518 | ${h.submit('save',_('Add'),class_="btn")} | |||
${h.reset('reset',_('Reset'),class_="btn")} | ||||
r1282 | </div> | |||
</div> | ||||
</div> | ||||
${h.end_form()} | ||||
</div> | ||||
</div> | ||||
</div> | ||||
<script> | ||||
r1518 | ||||
$(document).ready(function(){ | ||||
r2114 | ||||
r1518 | var select2Options = { | |||
'containerCssClass': "drop-menu", | ||||
'dropdownCssClass': "drop-menu-dropdown", | ||||
'dropdownAutoWidth': true | ||||
}; | ||||
$("#role").select2(select2Options); | ||||
r2083 | var preloadData = { | |||
results: [ | ||||
% for entry in c.lifetime_values: | ||||
{id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} | ||||
% endfor | ||||
] | ||||
}; | ||||
$("#lifetime").select2({ | ||||
containerCssClass: "drop-menu", | ||||
dropdownCssClass: "drop-menu-dropdown", | ||||
dropdownAutoWidth: true, | ||||
data: preloadData, | ||||
r2084 | placeholder: "${_('Select or enter expiration date')}", | |||
r2083 | query: function(query) { | |||
feedLifetimeOptions(query, preloadData); | ||||
} | ||||
}); | ||||
r1518 | var repoFilter = function(data) { | |||
var results = []; | ||||
if (!data.results[0]) { | ||||
return data | ||||
} | ||||
$.each(data.results[0].children, function() { | ||||
// replace name to ID for submision | ||||
r2774 | this.id = this.repo_id; | |||
r1518 | results.push(this); | |||
}); | ||||
data.results[0].children = results; | ||||
return data; | ||||
}; | ||||
$("#scope_repo_id_disabled").select2(select2Options); | ||||
r2118 | var selectVcsScope = function() { | |||
// select vcs scope and disable input | ||||
$("#role").select2("val", "${c.role_vcs}").trigger('change'); | ||||
$("#role").select2("readonly", true) | ||||
}; | ||||
r1518 | $("#scope_repo_id").select2({ | |||
cachedDataSource: {}, | ||||
minimumInputLength: 2, | ||||
placeholder: "${_('repository scope')}", | ||||
dropdownAutoWidth: true, | ||||
containerCssClass: "drop-menu", | ||||
dropdownCssClass: "drop-menu-dropdown", | ||||
r2774 | formatResult: formatRepoResult, | |||
r1518 | query: $.debounce(250, function(query){ | |||
self = this; | ||||
var cacheKey = query.term; | ||||
var cachedData = self.cachedDataSource[cacheKey]; | ||||
if (cachedData) { | ||||
query.callback({results: cachedData.results}); | ||||
} else { | ||||
$.ajax({ | ||||
r1667 | url: pyroutes.url('repo_list_data'), | |||
r1518 | data: {'query': query.term}, | |||
dataType: 'json', | ||||
type: 'GET', | ||||
success: function(data) { | ||||
data = repoFilter(data); | ||||
self.cachedDataSource[cacheKey] = data; | ||||
query.callback({results: data.results}); | ||||
}, | ||||
error: function(data, textStatus, errorThrown) { | ||||
alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); | ||||
} | ||||
r2114 | }) | |||
} | ||||
r1282 | }) | |||
r1518 | }); | |||
r2118 | $("#scope_repo_id").on('select2-selecting', function(e){ | |||
selectVcsScope() | ||||
}); | ||||
r1518 | ||||
}); | ||||
r1282 | </script> | |||