Show More
@@ -34,13 +34,18 b' log = logging.getLogger(__name__)' | |||
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | class MyAccountView(BaseAppView): |
|
37 | ALLOW_SCOPED_TOKENS = False | |
|
38 | """ | |
|
39 | This view has alternative version inside EE, if modified please take a look | |
|
40 | in there as well. | |
|
41 | """ | |
|
37 | 42 | |
|
38 | 43 | def load_default_context(self): |
|
39 | 44 | c = self._get_local_tmpl_context() |
|
40 | 45 | |
|
41 | 46 | c.auth_user = self.request.user |
|
42 | 47 | c.user = c.auth_user.get_instance() |
|
43 | ||
|
48 | c.allow_scoped_tokens = self.ALLOW_SCOPED_TOKENS | |
|
44 | 49 | self._register_global_c(c) |
|
45 | 50 | return c |
|
46 | 51 | |
@@ -55,8 +60,6 b' class MyAccountView(BaseAppView):' | |||
|
55 | 60 | c = self.load_default_context() |
|
56 | 61 | c.active = 'auth_tokens' |
|
57 | 62 | |
|
58 | show_expired = True | |
|
59 | ||
|
60 | 63 | c.lifetime_values = [ |
|
61 | 64 | (str(-1), _('forever')), |
|
62 | 65 | (str(5), _('5 minutes')), |
@@ -70,9 +73,13 b' class MyAccountView(BaseAppView):' | |||
|
70 | 73 | for x in AuthTokenModel.cls.ROLES] |
|
71 | 74 | c.role_options = [(c.role_values, _("Role"))] |
|
72 | 75 | c.user_auth_tokens = AuthTokenModel().get_auth_tokens( |
|
73 |
c.user.user_id, show_expired= |
|
|
76 | c.user.user_id, show_expired=True) | |
|
74 | 77 | return self._get_template_context(c) |
|
75 | 78 | |
|
79 | def maybe_attach_token_scope(self, token): | |
|
80 | # implemented in EE edition | |
|
81 | pass | |
|
82 | ||
|
76 | 83 | @LoginRequired() |
|
77 | 84 | @NotAnonymous() |
|
78 | 85 | @CSRFRequired() |
@@ -86,10 +93,12 b' class MyAccountView(BaseAppView):' | |||
|
86 | 93 | description = self.request.POST.get('description') |
|
87 | 94 | role = self.request.POST.get('role') |
|
88 | 95 | |
|
89 | AuthTokenModel().create(c.user.user_id, description, lifetime, role) | |
|
96 | token = AuthTokenModel().create( | |
|
97 | c.user.user_id, description, lifetime, role) | |
|
98 | self.maybe_attach_token_scope(token) | |
|
90 | 99 | Session().commit() |
|
100 | ||
|
91 | 101 | h.flash(_("Auth token successfully created"), category='success') |
|
92 | ||
|
93 | 102 | return HTTPFound(h.route_path('my_account_auth_tokens')) |
|
94 | 103 | |
|
95 | 104 | @LoginRequired() |
@@ -6,7 +6,6 b'' | |||
|
6 | 6 | <p> |
|
7 | 7 | ${_('Each token can have a role. Token with a role can be used only in given context, ' |
|
8 | 8 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} |
|
9 | ${_('Additionally scope for VCS type token can narrow the use to chosen repository.')} | |
|
10 | 9 | </p> |
|
11 | 10 | <table class="rctable auth_tokens"> |
|
12 | 11 | %if c.user_auth_tokens: |
@@ -70,7 +69,16 b'' | |||
|
70 | 69 | ${h.text('description', placeholder=_('Description'))} |
|
71 | 70 | ${h.select('lifetime', '', c.lifetime_options)} |
|
72 | 71 | ${h.select('role', '', c.role_options)} |
|
72 | ||
|
73 | % if c.allow_scoped_tokens: | |
|
74 | ${h.hidden('scope_repo_id')} | |
|
75 | % else: | |
|
76 | ${h.select('scope_repo_id_disabled', '', ['Scopes available in EE edition'], disabled='disabled')} | |
|
77 | % endif | |
|
73 | 78 | </div> |
|
79 | <p class="help-block"> | |
|
80 | ${_('Repository scope works only with tokens with VCS type.')} | |
|
81 | </p> | |
|
74 | 82 | </div> |
|
75 | 83 | <div class="buttons"> |
|
76 | 84 | ${h.submit('save',_('Add'),class_="btn")} |
@@ -82,14 +90,69 b'' | |||
|
82 | 90 | </div> |
|
83 | 91 | </div> |
|
84 | 92 | </div> |
|
85 |
|
|
|
86 |
|
|
|
87 | var select2Options = { | |
|
88 | 'containerCssClass': "drop-menu", | |
|
89 |
|
|
|
90 | 'dropdownAutoWidth': true | |
|
91 | }; | |
|
92 | $("#lifetime").select2(select2Options); | |
|
93 |
|
|
|
94 | }); | |
|
95 | </script> | |
|
93 | <script> | |
|
94 | $(document).ready(function(){ | |
|
95 | ||
|
96 | var select2Options = { | |
|
97 | 'containerCssClass': "drop-menu", | |
|
98 | 'dropdownCssClass': "drop-menu-dropdown", | |
|
99 | 'dropdownAutoWidth': true | |
|
100 | }; | |
|
101 | $("#lifetime").select2(select2Options); | |
|
102 | $("#role").select2(select2Options); | |
|
103 | ||
|
104 | var repoFilter = function(data) { | |
|
105 | var results = []; | |
|
106 | ||
|
107 | if (!data.results[0]) { | |
|
108 | return data | |
|
109 | } | |
|
110 | ||
|
111 | $.each(data.results[0].children, function() { | |
|
112 | // replace name to ID for submision | |
|
113 | this.id = this.obj.repo_id; | |
|
114 | results.push(this); | |
|
115 | }); | |
|
116 | ||
|
117 | data.results[0].children = results; | |
|
118 | return data; | |
|
119 | }; | |
|
120 | ||
|
121 | $("#scope_repo_id_disabled").select2(select2Options); | |
|
122 | ||
|
123 | $("#scope_repo_id").select2({ | |
|
124 | cachedDataSource: {}, | |
|
125 | minimumInputLength: 2, | |
|
126 | placeholder: "${_('repository scope')}", | |
|
127 | dropdownAutoWidth: true, | |
|
128 | containerCssClass: "drop-menu", | |
|
129 | dropdownCssClass: "drop-menu-dropdown", | |
|
130 | formatResult: formatResult, | |
|
131 | query: $.debounce(250, function(query){ | |
|
132 | self = this; | |
|
133 | var cacheKey = query.term; | |
|
134 | var cachedData = self.cachedDataSource[cacheKey]; | |
|
135 | ||
|
136 | if (cachedData) { | |
|
137 | query.callback({results: cachedData.results}); | |
|
138 | } else { | |
|
139 | $.ajax({ | |
|
140 | url: "${h.url('repo_list_data')}", | |
|
141 | data: {'query': query.term}, | |
|
142 | dataType: 'json', | |
|
143 | type: 'GET', | |
|
144 | success: function(data) { | |
|
145 | data = repoFilter(data); | |
|
146 | self.cachedDataSource[cacheKey] = data; | |
|
147 | query.callback({results: data.results}); | |
|
148 | }, | |
|
149 | error: function(data, textStatus, errorThrown) { | |
|
150 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); | |
|
151 | } | |
|
152 | }) | |
|
153 | } | |
|
154 | }) | |
|
155 | }); | |
|
156 | ||
|
157 | }); | |
|
158 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now