# HG changeset patch # User Marcin Kuzminski # Date 2017-03-03 16:54:07 # Node ID a630e423c764d7e44f79f2f572b8875ef299c13c # Parent 60d74bbcfd9bd3427f71d095b54c4b73393996e0 auth-tokens: extended views to allowed override of adding scope in EE edition. diff --git a/rhodecode/apps/my_account/views.py b/rhodecode/apps/my_account/views.py --- a/rhodecode/apps/my_account/views.py +++ b/rhodecode/apps/my_account/views.py @@ -34,13 +34,18 @@ log = logging.getLogger(__name__) class MyAccountView(BaseAppView): + ALLOW_SCOPED_TOKENS = False + """ + This view has alternative version inside EE, if modified please take a look + in there as well. + """ def load_default_context(self): c = self._get_local_tmpl_context() c.auth_user = self.request.user c.user = c.auth_user.get_instance() - + c.allow_scoped_tokens = self.ALLOW_SCOPED_TOKENS self._register_global_c(c) return c @@ -55,8 +60,6 @@ class MyAccountView(BaseAppView): c = self.load_default_context() c.active = 'auth_tokens' - show_expired = True - c.lifetime_values = [ (str(-1), _('forever')), (str(5), _('5 minutes')), @@ -70,9 +73,13 @@ class MyAccountView(BaseAppView): for x in AuthTokenModel.cls.ROLES] c.role_options = [(c.role_values, _("Role"))] c.user_auth_tokens = AuthTokenModel().get_auth_tokens( - c.user.user_id, show_expired=show_expired) + c.user.user_id, show_expired=True) return self._get_template_context(c) + def maybe_attach_token_scope(self, token): + # implemented in EE edition + pass + @LoginRequired() @NotAnonymous() @CSRFRequired() @@ -86,10 +93,12 @@ class MyAccountView(BaseAppView): description = self.request.POST.get('description') role = self.request.POST.get('role') - AuthTokenModel().create(c.user.user_id, description, lifetime, role) + token = AuthTokenModel().create( + c.user.user_id, description, lifetime, role) + self.maybe_attach_token_scope(token) Session().commit() + h.flash(_("Auth token successfully created"), category='success') - return HTTPFound(h.route_path('my_account_auth_tokens')) @LoginRequired() diff --git a/rhodecode/templates/admin/my_account/my_account_auth_tokens.mako b/rhodecode/templates/admin/my_account/my_account_auth_tokens.mako --- a/rhodecode/templates/admin/my_account/my_account_auth_tokens.mako +++ b/rhodecode/templates/admin/my_account/my_account_auth_tokens.mako @@ -6,7 +6,6 @@

${_('Each token can have a role. Token with a role can be used only in given context, ' 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} - ${_('Additionally scope for VCS type token can narrow the use to chosen repository.')}

%if c.user_auth_tokens: @@ -70,7 +69,16 @@ ${h.text('description', placeholder=_('Description'))} ${h.select('lifetime', '', c.lifetime_options)} ${h.select('role', '', c.role_options)} + + % 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 +

+ ${_('Repository scope works only with tokens with VCS type.')} +

${h.submit('save',_('Add'),class_="btn")} @@ -82,14 +90,69 @@
- +