Skip to content

Commit

Permalink
Add username_userid User ID factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Sep 3, 2023
1 parent e59c580 commit 9b63e9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Better handle values from identity data. @cekk

- Add `username_userid` User ID factory . @ericof


## 1.1.2 (2023-03-15)

Expand Down
4 changes: 4 additions & 0 deletions src/pas/plugins/authomatic/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
factory=".useridfactories.ProviderIDUserNameFactory"
name="username"
/>
<utility
factory=".useridfactories.ProviderIDUserNameIdFactory"
name="username_userid"
/>

</configure>
10 changes: 10 additions & 0 deletions src/pas/plugins/authomatic/useridfactories.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ def new_userid(plugin, result):
IUserIDFactory, name=settings.userid_factory_name, default=UUID4UserIDFactory()
)
return factory(plugin, result)


class ProviderIDUserNameIdFactory(BaseUserIDFactory):
title = _("Provider User Name or User ID")

def __call__(self, plugin, result):
user_id = result.user.username
if not user_id:
user_id = result.user.id
return self.normalize(plugin, result, user_id)

0 comments on commit 9b63e9d

Please sign in to comment.