Skip to content

Commit

Permalink
Check for name conflicts between stageusers and users
Browse files Browse the repository at this point in the history
Check if the username conflicts with an existing user. The check
is not perfect. A user might be created before the stage user is
activated. The code also suffers from a race condition. It's as
good as it can get without a better API, though.

closes #10

see https://fedorahosted.org/freeipa/ticket/5186
  • Loading branch information
tiran committed Aug 19, 2015
1 parent 9de324d commit d54963f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions freeipa_community_portal/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ def _call_api(self):
"""
api_connect()

# Check if the username conflicts with an existing user. The check
# is not perfect. A user might be created before the stage user is
# activated. The code also suffers from a race condition. It's as
# good as it can get without a better API, though.
# see https://fedorahosted.org/freeipa/ticket/5186
try:
api.Command.user_show(uid=self.username)
except errors.NotFound:
pass
else:
raise errors.DuplicateEntry(
message='active user with name "%(user)s" already exists' % {
'user': self.username
}
)

api.Command.stageuser_add( # pylint: disable=no-member
givenname=self.given_name,
sn=self.family_name,
Expand Down

0 comments on commit d54963f

Please sign in to comment.