Changeset - e3aab61a9411
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -251,7 +251,7 @@ class MyAccountController(BaseController
 
        description = request.POST.get('description')
 
        ApiKeyModel().create(self.authuser.user_id, description, lifetime)
 
        Session().commit()
 
        h.flash(_("Api key successfully created"), category='success')
 
        h.flash(_("API key successfully created"), category='success')
 
        return redirect(url('my_account_api_keys'))
 

	
 
    def my_account_api_keys_delete(self):
 
@@ -263,10 +263,10 @@ class MyAccountController(BaseController
 
                user.api_key = generate_api_key(user.username)
 
                Session().add(user)
 
                Session().commit()
 
                h.flash(_("Api key successfully reset"), category='success')
 
                h.flash(_("API key successfully reset"), category='success')
 
        elif api_key:
 
            ApiKeyModel().delete(api_key, self.authuser.user_id)
 
            Session().commit()
 
            h.flash(_("Api key successfully deleted"), category='success')
 
            h.flash(_("API key successfully deleted"), category='success')
 

	
 
        return redirect(url('my_account_api_keys'))
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -311,7 +311,7 @@ class UsersController(BaseController):
 
        description = request.POST.get('description')
 
        ApiKeyModel().create(c.user.user_id, description, lifetime)
 
        Session().commit()
 
        h.flash(_("Api key successfully created"), category='success')
 
        h.flash(_("API key successfully created"), category='success')
 
        return redirect(url('edit_user_api_keys', id=c.user.user_id))
 

	
 
    def delete_api_key(self, id):
 
@@ -327,11 +327,11 @@ class UsersController(BaseController):
 
                user.api_key = generate_api_key(user.username)
 
                Session().add(user)
 
                Session().commit()
 
                h.flash(_("Api key successfully reset"), category='success')
 
                h.flash(_("API key successfully reset"), category='success')
 
        elif api_key:
 
            ApiKeyModel().delete(api_key, c.user.user_id)
 
            Session().commit()
 
            h.flash(_("Api key successfully deleted"), category='success')
 
            h.flash(_("API key successfully deleted"), category='success')
 

	
 
        return redirect(url('edit_user_api_keys', id=c.user.user_id))
 

	
kallithea/controllers/api/__init__.py
Show inline comments
 
@@ -134,7 +134,7 @@ class JSONRPCController(WSGIController):
 
                                 message="JSON parse error ERR:%s RAW:%r"
 
                                 % (e, raw_body))
 

	
 
        # check AUTH based on API KEY
 
        # check AUTH based on API key
 
        try:
 
            self._req_api_key = json_body['api_key']
 
            self._req_id = json_body['id']
 
@@ -156,7 +156,7 @@ class JSONRPCController(WSGIController):
 
            u = User.get_by_api_key(self._req_api_key)
 
            if u is None:
 
                return jsonrpc_error(retid=self._req_id,
 
                                     message='Invalid API KEY')
 
                                     message='Invalid API key')
 

	
 
            #check if we are allowed to use this IP
 
            auth_u = AuthUser(u.user_id, self._req_api_key, ip_addr=ip_addr)
 
@@ -168,7 +168,7 @@ class JSONRPCController(WSGIController):
 

	
 
        except Exception, e:
 
            return jsonrpc_error(retid=self._req_id,
 
                                 message='Invalid API KEY')
 
                                 message='Invalid API key')
 

	
 
        self._error = None
 
        try:
 
@@ -208,7 +208,7 @@ class JSONRPCController(WSGIController):
 
        # get our arglist and check if we provided them as args
 
        for arg, default in func_kwargs.iteritems():
 
            if arg == USER_SESSION_ATTR:
 
                # USER_SESSION_ATTR is something translated from api key and
 
                # USER_SESSION_ATTR is something translated from API key and
 
                # this is checked before so we don't need validate it
 
                continue
 

	
kallithea/controllers/api/api.py
Show inline comments
 
@@ -553,7 +553,7 @@ class ApiController(JSONRPCController):
 
                    {
 
                        "user_id" :     "<user_id>",
 
                        "api_key" :     "<api_key>",
 
                        "api_keys":     "[<list of all api keys including additional ones>]"
 
                        "api_keys":     "[<list of all API keys including additional ones>]"
 
                        "username" :    "<username>",
 
                        "firstname":    "<firstname>",
 
                        "lastname" :    "<lastname>",
kallithea/lib/auth.py
Show inline comments
 
@@ -146,7 +146,7 @@ def check_password(password, hashed):
 

	
 
def generate_api_key(str_, salt=None):
 
    """
 
    Generates API KEY from given string
 
    Generates API key from given string
 

	
 
    :param str_:
 
    :param salt:
 
@@ -519,9 +519,9 @@ class AuthUser(object):
 
            log.debug('Auth User lookup by USER ID %s' % self.user_id)
 
            is_user_loaded = user_model.fill_data(self, user_id=self.user_id)
 

	
 
        # try go get user by api key
 
        # try go get user by API key
 
        elif self._api_key and self._api_key != self.anonymous_user.api_key:
 
            log.debug('Auth User lookup by API KEY %s' % self._api_key)
 
            log.debug('Auth User lookup by API key %s' % self._api_key)
 
            is_user_loaded = user_model.fill_data(self, api_key=self._api_key)
 

	
 
        # lookup by username
kallithea/lib/dbmigrate/schema/db_2_2_0.py
Show inline comments
 
@@ -437,7 +437,7 @@ class User(Base, BaseModel):
 
    user_comments = relationship('ChangesetComment', cascade='all')
 
    #extra emails for this user
 
    user_emails = relationship('UserEmailMap', cascade='all')
 
    #extra api keys
 
    #extra API keys
 
    user_api_keys = relationship('UserApiKeys', cascade='all')
 

	
 

	
kallithea/lib/dbmigrate/schema/db_2_2_3.py
Show inline comments
 
@@ -437,7 +437,7 @@ class User(Base, BaseModel):
 
    user_comments = relationship('ChangesetComment', cascade='all')
 
    #extra emails for this user
 
    user_emails = relationship('UserEmailMap', cascade='all')
 
    #extra api keys
 
    #extra API keys
 
    user_api_keys = relationship('UserApiKeys', cascade='all')
 

	
 

	
kallithea/model/api_key.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
kallithea.model.api_key
 
~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
api key model for Kallithea
 
API key model for Kallithea
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
kallithea/model/db.py
Show inline comments
 
@@ -438,7 +438,7 @@ class User(Base, BaseModel):
 
    user_comments = relationship('ChangesetComment', cascade='all')
 
    #extra emails for this user
 
    user_emails = relationship('UserEmailMap', cascade='all')
 
    #extra api keys
 
    #extra API keys
 
    user_api_keys = relationship('UserApiKeys', cascade='all')
 

	
 

	
kallithea/model/user.py
Show inline comments
 
@@ -349,7 +349,7 @@ class UserModel(BaseModel):
 

	
 
        :param auth_user: instance of user to set attributes
 
        :param user_id: user id to fetch by
 
        :param api_key: api key to fetch by
 
        :param api_key: API key to fetch by
 
        :param username: username to fetch by
 
        """
 
        if user_id is None and api_key is None and username is None:
kallithea/templates/admin/my_account/my_account_api_keys.html
Show inline comments
 
@@ -11,7 +11,7 @@
 
                ${h.hidden('del_api_key',c.user.api_key)}
 
                ${h.hidden('del_api_key_builtin',1)}
 
                <button class="btn btn-mini btn-danger" type="submit"
 
                        onclick="return confirm('${_('Confirm to reset this api key: %s') % c.user.api_key}');">
 
                        onclick="return confirm('${_('Confirm to reset this API key: %s') % c.user.api_key}');">
 
                    ${_('reset')}
 
                </button>
 
            ${h.end_form()}
 
@@ -37,7 +37,7 @@
 
                ${h.form(url('my_account_api_keys'),method='delete')}
 
                    ${h.hidden('del_api_key',api_key.api_key)}
 
                    <button class="btn btn-mini btn-danger" type="submit"
 
                            onclick="return confirm('${_('Confirm to remove this api key: %s') % api_key.api_key}');">
 
                            onclick="return confirm('${_('Confirm to remove this API key: %s') % api_key.api_key}');">
 
                        <i class="icon-minus-circled"></i>
 
                        ${_('remove')}
 
                    </button>
 
@@ -46,7 +46,7 @@
 
          </tr>
 
        %endfor
 
    %else:
 
    <tr><td><div class="ip">${_('No additional api keys specified')}</div></td></tr>
 
    <tr><td><div class="ip">${_('No additional API keys specified')}</div></td></tr>
 
    %endif
 
  </table>
 
</div>
 
@@ -58,7 +58,7 @@
 
        <div class="fields">
 
             <div class="field">
 
                <div class="label">
 
                    <label for="description">${_('New api key')}:</label>
 
                    <label for="description">${_('New API key')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('description', class_='medium', placeholder=_('Description'))}
kallithea/templates/admin/users/user_edit_api_keys.html
Show inline comments
 
@@ -11,7 +11,7 @@
 
                ${h.hidden('del_api_key',c.user.api_key)}
 
                ${h.hidden('del_api_key_builtin',1)}
 
                <button class="btn btn-mini btn-danger" type="submit"
 
                        onclick="return confirm('${_('Confirm to reset this api key: %s') % c.user.api_key}');">
 
                        onclick="return confirm('${_('Confirm to reset this API key: %s') % c.user.api_key}');">
 
                    ${_('reset')}
 
                </button>
 
            ${h.end_form()}
 
@@ -37,7 +37,7 @@
 
                ${h.form(url('edit_user_api_keys', id=c.user.user_id),method='delete')}
 
                    ${h.hidden('del_api_key',api_key.api_key)}
 
                    <button class="btn btn-mini btn-danger" type="submit"
 
                            onclick="return confirm('${_('Confirm to remove this api key: %s') % api_key.api_key}');">
 
                            onclick="return confirm('${_('Confirm to remove this API key: %s') % api_key.api_key}');">
 
                        <i class="icon-minus-circled"></i>
 
                        ${_('remove')}
 
                    </button>
 
@@ -46,7 +46,7 @@
 
          </tr>
 
        %endfor
 
    %else:
 
    <tr><td><div class="ip">${_('No additional api keys specified')}</div></td></tr>
 
    <tr><td><div class="ip">${_('No additional API keys specified')}</div></td></tr>
 
    %endif
 
  </table>
 
</div>
 
@@ -58,7 +58,7 @@
 
        <div class="fields">
 
             <div class="field">
 
                <div class="label">
 
                    <label for="description">${_('New api key')}:</label>
 
                    <label for="description">${_('New API key')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('description', class_='medium', placeholder=_('Description'))}
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -166,7 +166,7 @@ class _BaseTestApi(object):
 
        id_, params = _build_data('trololo', 'get_user')
 
        response = api_call(self, params)
 

	
 
        expected = 'Invalid API KEY'
 
        expected = 'Invalid API key'
 
        self._compare_error(id_, expected, given=response.body)
 

	
 
    def test_api_missing_non_optional_param(self):
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -452,7 +452,7 @@ class TestAdminUsersController(TestContr
 

	
 
        response = self.app.post(url('edit_user_api_keys', id=user_id),
 
                 {'_method': 'put', 'description': desc, 'lifetime': lifetime, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully created')
 
        self.checkSessionFlash(response, 'API key successfully created')
 
        try:
 
            response = response.follow()
 
            user = User.get(user_id)
 
@@ -470,7 +470,7 @@ class TestAdminUsersController(TestContr
 

	
 
        response = self.app.post(url('edit_user_api_keys', id=user_id),
 
                {'_method': 'put', 'description': 'desc', 'lifetime': -1, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully created')
 
        self.checkSessionFlash(response, 'API key successfully created')
 
        response = response.follow()
 

	
 
        #now delete our key
 
@@ -479,7 +479,7 @@ class TestAdminUsersController(TestContr
 

	
 
        response = self.app.post(url('edit_user_api_keys', id=user_id),
 
                 {'_method': 'delete', 'del_api_key': keys[0].api_key, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully deleted')
 
        self.checkSessionFlash(response, 'API key successfully deleted')
 
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
 
        self.assertEqual(0, len(keys))
 

	
 
@@ -494,6 +494,6 @@ class TestAdminUsersController(TestContr
 

	
 
        response = self.app.post(url('edit_user_api_keys', id=user_id),
 
                 {'_method': 'delete', 'del_api_key_builtin': api_key, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully reset')
 
        self.checkSessionFlash(response, 'API key successfully reset')
 
        response = response.follow()
 
        response.mustcontain(no=[api_key])
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -363,7 +363,7 @@ class TestLoginController(TestController
 

	
 
            new_api_key = ApiKeyModel().create(TEST_USER_ADMIN_LOGIN, u'test')
 
            Session().commit()
 
            #patch the api key and make it expired
 
            #patch the API key and make it expired
 
            new_api_key.expires = 0
 
            Session().add(new_api_key)
 
            Session().commit()
kallithea/tests/functional/test_my_account.py
Show inline comments
 
@@ -201,7 +201,7 @@ class TestMyAccountController(TestContro
 
        user = User.get(usr['user_id'])
 
        response = self.app.post(url('my_account_api_keys'),
 
                                 {'description': desc, 'lifetime': lifetime, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully created')
 
        self.checkSessionFlash(response, 'API key successfully created')
 
        try:
 
            response = response.follow()
 
            user = User.get(usr['user_id'])
 
@@ -217,7 +217,7 @@ class TestMyAccountController(TestContro
 
        user = User.get(usr['user_id'])
 
        response = self.app.post(url('my_account_api_keys'),
 
                                 {'description': 'desc', 'lifetime': -1, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully created')
 
        self.checkSessionFlash(response, 'API key successfully created')
 
        response = response.follow()
 

	
 
        #now delete our key
 
@@ -226,7 +226,7 @@ class TestMyAccountController(TestContro
 

	
 
        response = self.app.post(url('my_account_api_keys'),
 
                 {'_method': 'delete', 'del_api_key': keys[0].api_key, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully deleted')
 
        self.checkSessionFlash(response, 'API key successfully deleted')
 
        keys = UserApiKeys.query().all()
 
        self.assertEqual(0, len(keys))
 

	
 
@@ -241,6 +241,6 @@ class TestMyAccountController(TestContro
 

	
 
        response = self.app.post(url('my_account_api_keys'),
 
                 {'_method': 'delete', 'del_api_key_builtin': api_key, '_authentication_token': self.authentication_token()})
 
        self.checkSessionFlash(response, 'Api key successfully reset')
 
        self.checkSessionFlash(response, 'API key successfully reset')
 
        response = response.follow()
 
        response.mustcontain(no=[api_key])
0 comments (0 inline, 0 general)