aboutsummaryrefslogtreecommitdiff
path: root/rhodecode
diff options
context:
space:
mode:
authorMarcin Kuzminski <marcin@python-works.com>2012-06-26 21:57:31 +0200
committerMarcin Kuzminski <marcin@python-works.com>2012-06-26 21:57:31 +0200
commit9b87c9714ccaca0aa3525200e135a552768dcaa5 (patch)
tree9f84d8c5cc57a1eb0802484f78f2463080fc1d5c /rhodecode
parent53a7a1b00ff1d43b31c914f96bb9c1c3e27de3a7 (diff)
Updated create_or_update method to not change API key when password is not updated
--HG-- branch : beta
Diffstat (limited to 'rhodecode')
-rw-r--r--rhodecode/lib/db_manage.py4
-rw-r--r--rhodecode/model/user.py16
-rw-r--r--rhodecode/tests/functional/test_admin_notifications.py29
-rw-r--r--rhodecode/tests/functional/test_forks.py2
-rw-r--r--rhodecode/tests/test_models.py16
5 files changed, 29 insertions, 38 deletions
diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py
index 2a5f3b61..0dd63d63 100644
--- a/rhodecode/lib/db_manage.py
+++ b/rhodecode/lib/db_manage.py
@@ -465,7 +465,7 @@ class DbManage(object):
def create_user(self, username, password, email='', admin=False):
log.info('creating user %s' % username)
UserModel().create_or_update(username, password, email,
- name='RhodeCode', lastname='Admin',
+ firstname='RhodeCode', lastname='Admin',
active=True, admin=admin)
def create_default_user(self):
@@ -474,7 +474,7 @@ class DbManage(object):
UserModel().create_or_update(username='default',
password=str(uuid.uuid1())[:8],
email='anonymous@rhodecode.org',
- name='Anonymous', lastname='User')
+ firstname='Anonymous', lastname='User')
def create_permissions(self):
# module.(access|create|change|delete)_[name]
diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py
index 4e5c559a..5b4f9595 100644
--- a/rhodecode/model/user.py
+++ b/rhodecode/model/user.py
@@ -101,8 +101,8 @@ class UserModel(BaseModel):
log.error(traceback.format_exc())
raise
- def create_or_update(self, username, password, email, name, lastname,
- active=True, admin=False, ldap_dn=None):
+ def create_or_update(self, username, password, email, firstname='',
+ lastname='', active=True, admin=False, ldap_dn=None):
"""
Creates a new instance if not found, or updates current one
@@ -110,7 +110,7 @@ class UserModel(BaseModel):
:param password:
:param email:
:param active:
- :param name:
+ :param firstname:
:param lastname:
:param active:
:param admin:
@@ -124,19 +124,23 @@ class UserModel(BaseModel):
if user is None:
log.debug('creating new user %s' % username)
new_user = User()
+ edit = False
else:
log.debug('updating user %s' % username)
new_user = user
+ edit = True
try:
new_user.username = username
new_user.admin = admin
- new_user.password = get_crypt_password(password)
- new_user.api_key = generate_api_key(username)
+ # set password only if creating an user or password is changed
+ if edit is False or user.password != password:
+ new_user.password = get_crypt_password(password)
+ new_user.api_key = generate_api_key(username)
new_user.email = email
new_user.active = active
new_user.ldap_dn = safe_unicode(ldap_dn) if ldap_dn else None
- new_user.name = name
+ new_user.name = firstname
new_user.lastname = lastname
self.sa.add(new_user)
return new_user
diff --git a/rhodecode/tests/functional/test_admin_notifications.py b/rhodecode/tests/functional/test_admin_notifications.py
index e8ee33fe..098f2974 100644
--- a/rhodecode/tests/functional/test_admin_notifications.py
+++ b/rhodecode/tests/functional/test_admin_notifications.py
@@ -5,8 +5,8 @@ from rhodecode.model.user import UserModel
from rhodecode.model.notification import NotificationModel
from rhodecode.model.meta import Session
-class TestNotificationsController(TestController):
+class TestNotificationsController(TestController):
def tearDown(self):
for n in Notification.query().all():
@@ -19,7 +19,8 @@ class TestNotificationsController(TestController):
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@rhodecode.org',
- name='u1', lastname='u1').user_id
+ firstname='u1', lastname='u1')
+ u1 = u1.user_id
response = self.app.get(url('notifications'))
self.assertTrue('''<div class="table">No notifications here yet</div>'''
@@ -58,10 +59,10 @@ class TestNotificationsController(TestController):
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@rhodecode.org',
- name='u1', lastname='u1')
+ firstname='u1', lastname='u1')
u2 = UserModel().create_or_update(username='u2', password='qweqwe',
email='u2@rhodecode.org',
- name='u2', lastname='u2')
+ firstname='u2', lastname='u2')
# make notifications
notification = NotificationModel().create(created_by=cur_user,
@@ -73,13 +74,12 @@ class TestNotificationsController(TestController):
u2 = User.get(u2.user_id)
# check DB
- get_notif = lambda un:[x.notification for x in un]
+ get_notif = lambda un: [x.notification for x in un]
self.assertEqual(get_notif(cur_user.notifications), [notification])
self.assertEqual(get_notif(u1.notifications), [notification])
self.assertEqual(get_notif(u2.notifications), [notification])
cur_usr_id = cur_user.user_id
-
response = self.app.delete(url('notification',
notification_id=
notification.notification_id))
@@ -87,19 +87,15 @@ class TestNotificationsController(TestController):
cur_user = User.get(cur_usr_id)
self.assertEqual(cur_user.notifications, [])
-
-# def test_delete_browser_fakeout(self):
-# response = self.app.post(url('notification', notification_id=1), params=dict(_method='delete'))
-
def test_show(self):
self.log_user()
cur_user = self._get_logged_user()
u1 = UserModel().create_or_update(username='u1', password='qweqwe',
email='u1@rhodecode.org',
- name='u1', lastname='u1')
+ firstname='u1', lastname='u1')
u2 = UserModel().create_or_update(username='u2', password='qweqwe',
email='u2@rhodecode.org',
- name='u2', lastname='u2')
+ firstname='u2', lastname='u2')
notification = NotificationModel().create(created_by=cur_user,
subject=u'test',
@@ -108,12 +104,3 @@ class TestNotificationsController(TestController):
response = self.app.get(url('notification',
notification_id=notification.notification_id))
-
-# def test_show_as_xml(self):
-# response = self.app.get(url('formatted_notification', notification_id=1, format='xml'))
-#
-# def test_edit(self):
-# response = self.app.get(url('edit_notification', notification_id=1))
-#
-# def test_edit_as_xml(self):
-# response = self.app.get(url('formatted_edit_notification', notification_id=1, format='xml'))
diff --git a/rhodecode/tests/functional/test_forks.py b/rhodecode/tests/functional/test_forks.py
index 72dd8a10..2214e9cb 100644
--- a/rhodecode/tests/functional/test_forks.py
+++ b/rhodecode/tests/functional/test_forks.py
@@ -12,7 +12,7 @@ class TestForksController(TestController):
self.password = u'qweqwe'
self.u1 = UserModel().create_or_update(
username=self.username, password=self.password,
- email=u'fork_king@rhodecode.org', name=u'u1', lastname=u'u1'
+ email=u'fork_king@rhodecode.org', firstname=u'u1', lastname=u'u1'
)
self.Session.commit()
diff --git a/rhodecode/tests/test_models.py b/rhodecode/tests/test_models.py
index c16fd8b6..4e016269 100644
--- a/rhodecode/tests/test_models.py
+++ b/rhodecode/tests/test_models.py
@@ -185,7 +185,7 @@ class TestUser(unittest.TestCase):
usr = UserModel().create_or_update(username=u'test_user',
password=u'qweqwe',
email=u'u232@rhodecode.org',
- name=u'u1', lastname=u'u1')
+ firstname=u'u1', lastname=u'u1')
Session.commit()
self.assertEqual(User.get_by_username(u'test_user'), usr)
@@ -207,7 +207,7 @@ class TestUser(unittest.TestCase):
usr = UserModel().create_or_update(username=u'test_user',
password=u'qweqwe',
email=u'main_email@rhodecode.org',
- name=u'u1', lastname=u'u1')
+ firstname=u'u1', lastname=u'u1')
Session.commit()
def do():
@@ -225,7 +225,7 @@ class TestUser(unittest.TestCase):
usr = UserModel().create_or_update(username=u'test_user',
password=u'qweqwe',
email=u'main_email@rhodecode.org',
- name=u'u1', lastname=u'u1')
+ firstname=u'u1', lastname=u'u1')
Session.commit()
m = UserEmailMap()
@@ -255,7 +255,7 @@ class TestNotifications(unittest.TestCase):
self.u1 = UserModel().create_or_update(username=u'u1',
password=u'qweqwe',
email=u'u1@rhodecode.org',
- name=u'u1', lastname=u'u1')
+ firstname=u'u1', lastname=u'u1')
Session.commit()
self.u1 = self.u1.user_id
@@ -433,7 +433,7 @@ class TestUsers(unittest.TestCase):
self.u1 = UserModel().create_or_update(username=u'u1',
password=u'qweqwe',
email=u'u1@rhodecode.org',
- name=u'u1', lastname=u'u1')
+ firstname=u'u1', lastname=u'u1')
def tearDown(self):
perm = Permission.query().all()
@@ -474,16 +474,16 @@ class TestPermissions(unittest.TestCase):
def setUp(self):
self.u1 = UserModel().create_or_update(
username=u'u1', password=u'qweqwe',
- email=u'u1@rhodecode.org', name=u'u1', lastname=u'u1'
+ email=u'u1@rhodecode.org', firstname=u'u1', lastname=u'u1'
)
self.u2 = UserModel().create_or_update(
username=u'u2', password=u'qweqwe',
- email=u'u2@rhodecode.org', name=u'u2', lastname=u'u2'
+ email=u'u2@rhodecode.org', firstname=u'u2', lastname=u'u2'
)
self.anon = User.get_by_username('default')
self.a1 = UserModel().create_or_update(
username=u'a1', password=u'qweqwe',
- email=u'a1@rhodecode.org', name=u'a1', lastname=u'a1', admin=True
+ email=u'a1@rhodecode.org', firstname=u'a1', lastname=u'a1', admin=True
)
Session.commit()