Show More
@@ -18,6 +18,7 b'' | |||
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | import time | |
|
21 | 22 | import logging |
|
22 | 23 | import datetime |
|
23 | 24 | import formencode |
@@ -177,14 +178,7 b' class AdminUsersView(BaseAppView, DataGr' | |||
|
177 | 178 | |
|
178 | 179 | c.active = 'auth_tokens' |
|
179 | 180 | |
|
180 | c.lifetime_values = [ | |
|
181 | (str(-1), _('forever')), | |
|
182 | (str(5), _('5 minutes')), | |
|
183 | (str(60), _('1 hour')), | |
|
184 | (str(60 * 24), _('1 day')), | |
|
185 | (str(60 * 24 * 30), _('1 month')), | |
|
186 | ] | |
|
187 | c.lifetime_options = [(c.lifetime_values, _("Lifetime"))] | |
|
181 | c.lifetime_values = AuthTokenModel.get_lifetime_values(translator=_) | |
|
188 | 182 | c.role_values = [ |
|
189 | 183 | (x, AuthTokenModel.cls._get_role_name(x)) |
|
190 | 184 | for x in AuthTokenModel.cls.ROLES] |
@@ -152,15 +152,7 b' class MyAccountView(BaseAppView, DataGri' | |||
|
152 | 152 | |
|
153 | 153 | c = self.load_default_context() |
|
154 | 154 | c.active = 'auth_tokens' |
|
155 | ||
|
156 | c.lifetime_values = [ | |
|
157 | (str(-1), _('forever')), | |
|
158 | (str(5), _('5 minutes')), | |
|
159 | (str(60), _('1 hour')), | |
|
160 | (str(60 * 24), _('1 day')), | |
|
161 | (str(60 * 24 * 30), _('1 month')), | |
|
162 | ] | |
|
163 | c.lifetime_options = [(c.lifetime_values, _("Lifetime"))] | |
|
155 | c.lifetime_values = AuthTokenModel.get_lifetime_values(translator=_) | |
|
164 | 156 | c.role_values = [ |
|
165 | 157 | (x, AuthTokenModel.cls._get_role_name(x)) |
|
166 | 158 | for x in AuthTokenModel.cls.ROLES] |
@@ -37,6 +37,28 b' log = logging.getLogger(__name__)' | |||
|
37 | 37 | class AuthTokenModel(BaseModel): |
|
38 | 38 | cls = UserApiKeys |
|
39 | 39 | |
|
40 | @classmethod | |
|
41 | def get_lifetime_values(cls, translator): | |
|
42 | from rhodecode.lib import helpers as h | |
|
43 | _ = translator | |
|
44 | ||
|
45 | def date_after_min(mins): | |
|
46 | after = time.time() + (60 * mins) | |
|
47 | return h.format_date(h.time_to_datetime(after)) | |
|
48 | ||
|
49 | return [ | |
|
50 | (str(-1), | |
|
51 | _('forever')), | |
|
52 | (str(5), | |
|
53 | _('5 minutes {end_date}').format(end_date=date_after_min(5))), | |
|
54 | (str(60), | |
|
55 | _('1 hour {end_date}').format(end_date=date_after_min(60))), | |
|
56 | (str(60 * 24), | |
|
57 | _('1 day {end_date}').format(end_date=date_after_min(60 * 24))), | |
|
58 | (str(60 * 24 * 30), | |
|
59 | _('1 month {end_date}').format(end_date=date_after_min(60 * 24 * 30))), | |
|
60 | ] | |
|
61 | ||
|
40 | 62 | def create(self, user, description, lifetime=-1, role=UserApiKeys.ROLE_ALL): |
|
41 | 63 | """ |
|
42 | 64 | :param user: user or user_id |
@@ -499,3 +499,62 b' function scrollToElement(element, percen' | |||
|
499 | 499 | } |
|
500 | 500 | collapsableContent(); |
|
501 | 501 | }); |
|
502 | ||
|
503 | var feedLifetimeOptions = function(query, initialData){ | |
|
504 | var data = {results: []}; | |
|
505 | var isQuery = typeof query.term !== 'undefined'; | |
|
506 | ||
|
507 | var section = _gettext('Lifetime'); | |
|
508 | var children = []; | |
|
509 | ||
|
510 | //filter results | |
|
511 | $.each(initialData.results, function(idx, value) { | |
|
512 | ||
|
513 | if (!isQuery || query.term.length === 0 || value.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) { | |
|
514 | children.push({ | |
|
515 | 'id': this.id, | |
|
516 | 'text': this.text | |
|
517 | }) | |
|
518 | } | |
|
519 | ||
|
520 | }); | |
|
521 | data.results.push({ | |
|
522 | 'text': section, | |
|
523 | 'children': children | |
|
524 | }); | |
|
525 | ||
|
526 | if (isQuery) { | |
|
527 | ||
|
528 | var now = moment.utc(); | |
|
529 | ||
|
530 | var parseQuery = function(entry, now){ | |
|
531 | var fmt = 'DD/MM/YYYY H:mm'; | |
|
532 | var parsed = moment.utc(entry, fmt); | |
|
533 | var diffInMin = parsed.diff(now, 'minutes'); | |
|
534 | ||
|
535 | if (diffInMin > 0){ | |
|
536 | return { | |
|
537 | id: diffInMin, | |
|
538 | text: parsed.format(fmt) | |
|
539 | } | |
|
540 | } else { | |
|
541 | return { | |
|
542 | id: undefined, | |
|
543 | text: parsed.format('DD/MM/YYYY') + ' ' + _gettext('date not in future') | |
|
544 | } | |
|
545 | } | |
|
546 | ||
|
547 | ||
|
548 | }; | |
|
549 | ||
|
550 | data.results.push({ | |
|
551 | 'text': _gettext('Specified expiration date'), | |
|
552 | 'children': [{ | |
|
553 | 'id': parseQuery(query.term, now).id, | |
|
554 | 'text': parseQuery(query.term, now).text | |
|
555 | }] | |
|
556 | }); | |
|
557 | } | |
|
558 | ||
|
559 | query.callback(data); | |
|
560 | }; |
@@ -69,7 +69,7 b'' | |||
|
69 | 69 | </div> |
|
70 | 70 | <div class="input"> |
|
71 | 71 | ${h.text('description', class_='medium', placeholder=_('Description'))} |
|
72 |
${h. |
|
|
72 | ${h.hidden('lifetime')} | |
|
73 | 73 | ${h.select('role', '', c.role_options)} |
|
74 | 74 | |
|
75 | 75 | % if c.allow_scoped_tokens: |
@@ -100,9 +100,29 b' var select2Options = {' | |||
|
100 | 100 | 'dropdownCssClass': "drop-menu-dropdown", |
|
101 | 101 | 'dropdownAutoWidth': true |
|
102 | 102 | }; |
|
103 | $("#lifetime").select2(select2Options); | |
|
104 | 103 | $("#role").select2(select2Options); |
|
105 | 104 | |
|
105 | ||
|
106 | var preloadData = { | |
|
107 | results: [ | |
|
108 | % for entry in c.lifetime_values: | |
|
109 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} | |
|
110 | % endfor | |
|
111 | ] | |
|
112 | }; | |
|
113 | ||
|
114 | $("#lifetime").select2({ | |
|
115 | containerCssClass: "drop-menu", | |
|
116 | dropdownCssClass: "drop-menu-dropdown", | |
|
117 | dropdownAutoWidth: true, | |
|
118 | data: preloadData, | |
|
119 | placeholder: ${_('Select or enter expiration date')}, | |
|
120 | query: function(query) { | |
|
121 | feedLifetimeOptions(query, preloadData); | |
|
122 | } | |
|
123 | }); | |
|
124 | ||
|
125 | ||
|
106 | 126 | var repoFilter = function(data) { |
|
107 | 127 | var results = []; |
|
108 | 128 |
@@ -65,7 +65,7 b'' | |||
|
65 | 65 | </div> |
|
66 | 66 | <div class="input"> |
|
67 | 67 | ${h.text('description', class_='medium', placeholder=_('Description'))} |
|
68 |
${h. |
|
|
68 | ${h.hidden('lifetime')} | |
|
69 | 69 | ${h.select('role', '', c.role_options)} |
|
70 | 70 | |
|
71 | 71 | % if c.allow_scoped_tokens: |
@@ -97,9 +97,28 b' var select2Options = {' | |||
|
97 | 97 | 'dropdownCssClass': "drop-menu-dropdown", |
|
98 | 98 | 'dropdownAutoWidth': true |
|
99 | 99 | }; |
|
100 | $("#lifetime").select2(select2Options); | |
|
101 | 100 | $("#role").select2(select2Options); |
|
102 | 101 | |
|
102 | var preloadData = { | |
|
103 | results: [ | |
|
104 | % for entry in c.lifetime_values: | |
|
105 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} | |
|
106 | % endfor | |
|
107 | ] | |
|
108 | }; | |
|
109 | ||
|
110 | $("#lifetime").select2({ | |
|
111 | containerCssClass: "drop-menu", | |
|
112 | dropdownCssClass: "drop-menu-dropdown", | |
|
113 | dropdownAutoWidth: true, | |
|
114 | data: preloadData, | |
|
115 | placeholder: ${_('Select or enter expiration date')}, | |
|
116 | query: function(query) { | |
|
117 | feedLifetimeOptions(query, preloadData); | |
|
118 | } | |
|
119 | }); | |
|
120 | ||
|
121 | ||
|
103 | 122 | var repoFilter = function(data) { |
|
104 | 123 | var results = []; |
|
105 | 124 |
General Comments 0
You need to be logged in to leave comments.
Login now