Show More
@@ -34,13 +34,18 b' log = logging.getLogger(__name__)' | |||||
34 |
|
34 | |||
35 |
|
35 | |||
36 | class MyAccountView(BaseAppView): |
|
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 | def load_default_context(self): |
|
43 | def load_default_context(self): | |
39 | c = self._get_local_tmpl_context() |
|
44 | c = self._get_local_tmpl_context() | |
40 |
|
45 | |||
41 | c.auth_user = self.request.user |
|
46 | c.auth_user = self.request.user | |
42 | c.user = c.auth_user.get_instance() |
|
47 | c.user = c.auth_user.get_instance() | |
43 |
|
48 | c.allow_scoped_tokens = self.ALLOW_SCOPED_TOKENS | ||
44 | self._register_global_c(c) |
|
49 | self._register_global_c(c) | |
45 | return c |
|
50 | return c | |
46 |
|
51 | |||
@@ -55,8 +60,6 b' class MyAccountView(BaseAppView):' | |||||
55 | c = self.load_default_context() |
|
60 | c = self.load_default_context() | |
56 | c.active = 'auth_tokens' |
|
61 | c.active = 'auth_tokens' | |
57 |
|
62 | |||
58 | show_expired = True |
|
|||
59 |
|
||||
60 | c.lifetime_values = [ |
|
63 | c.lifetime_values = [ | |
61 | (str(-1), _('forever')), |
|
64 | (str(-1), _('forever')), | |
62 | (str(5), _('5 minutes')), |
|
65 | (str(5), _('5 minutes')), | |
@@ -70,9 +73,13 b' class MyAccountView(BaseAppView):' | |||||
70 | for x in AuthTokenModel.cls.ROLES] |
|
73 | for x in AuthTokenModel.cls.ROLES] | |
71 | c.role_options = [(c.role_values, _("Role"))] |
|
74 | c.role_options = [(c.role_values, _("Role"))] | |
72 | c.user_auth_tokens = AuthTokenModel().get_auth_tokens( |
|
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 | return self._get_template_context(c) |
|
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 | @LoginRequired() |
|
83 | @LoginRequired() | |
77 | @NotAnonymous() |
|
84 | @NotAnonymous() | |
78 | @CSRFRequired() |
|
85 | @CSRFRequired() | |
@@ -86,10 +93,12 b' class MyAccountView(BaseAppView):' | |||||
86 | description = self.request.POST.get('description') |
|
93 | description = self.request.POST.get('description') | |
87 | role = self.request.POST.get('role') |
|
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 | Session().commit() |
|
99 | Session().commit() | |
|
100 | ||||
91 | h.flash(_("Auth token successfully created"), category='success') |
|
101 | h.flash(_("Auth token successfully created"), category='success') | |
92 |
|
||||
93 | return HTTPFound(h.route_path('my_account_auth_tokens')) |
|
102 | return HTTPFound(h.route_path('my_account_auth_tokens')) | |
94 |
|
103 | |||
95 | @LoginRequired() |
|
104 | @LoginRequired() |
@@ -6,7 +6,6 b'' | |||||
6 | <p> |
|
6 | <p> | |
7 | ${_('Each token can have a role. Token with a role can be used only in given context, ' |
|
7 | ${_('Each token can have a role. Token with a role can be used only in given context, ' | |
8 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} |
|
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 | </p> |
|
9 | </p> | |
11 | <table class="rctable auth_tokens"> |
|
10 | <table class="rctable auth_tokens"> | |
12 | %if c.user_auth_tokens: |
|
11 | %if c.user_auth_tokens: | |
@@ -70,7 +69,16 b'' | |||||
70 | ${h.text('description', placeholder=_('Description'))} |
|
69 | ${h.text('description', placeholder=_('Description'))} | |
71 | ${h.select('lifetime', '', c.lifetime_options)} |
|
70 | ${h.select('lifetime', '', c.lifetime_options)} | |
72 | ${h.select('role', '', c.role_options)} |
|
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 | </div> |
|
78 | </div> | |
|
79 | <p class="help-block"> | |||
|
80 | ${_('Repository scope works only with tokens with VCS type.')} | |||
|
81 | </p> | |||
74 | </div> |
|
82 | </div> | |
75 | <div class="buttons"> |
|
83 | <div class="buttons"> | |
76 | ${h.submit('save',_('Add'),class_="btn")} |
|
84 | ${h.submit('save',_('Add'),class_="btn")} | |
@@ -82,14 +90,69 b'' | |||||
82 | </div> |
|
90 | </div> | |
83 | </div> |
|
91 | </div> | |
84 | </div> |
|
92 | </div> | |
85 |
|
|
93 | <script> | |
86 |
|
|
94 | $(document).ready(function(){ | |
87 | var select2Options = { |
|
95 | ||
88 | 'containerCssClass': "drop-menu", |
|
96 | var select2Options = { | |
89 |
|
|
97 | 'containerCssClass': "drop-menu", | |
90 | 'dropdownAutoWidth': true |
|
98 | 'dropdownCssClass': "drop-menu-dropdown", | |
91 | }; |
|
99 | 'dropdownAutoWidth': true | |
92 | $("#lifetime").select2(select2Options); |
|
100 | }; | |
93 |
|
|
101 | $("#lifetime").select2(select2Options); | |
94 | }); |
|
102 | $("#role").select2(select2Options); | |
95 | </script> |
|
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