also sync recent user changes (#26071)
This commit is contained in:
parent
dd9e9977ae
commit
ac3dcae4a2
|
@ -14,6 +14,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -55,6 +56,24 @@ class Command(BaseCommand):
|
||||||
account.user.save()
|
account.user.save()
|
||||||
OIDCAccount.objects.filter(sub__in=unknown_uuids).delete()
|
OIDCAccount.objects.filter(sub__in=unknown_uuids).delete()
|
||||||
|
|
||||||
|
# update recently modified users
|
||||||
|
cut_users = OIDCProvider.objects.get(name='cut')
|
||||||
|
url = settings.CUT_API_BASE_URL + 'users/?modified__gt=%s' % (
|
||||||
|
datetime.datetime.now() - datetime.timedelta(seconds=120)).strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
|
resp = requests.get(url, auth=settings.CUT_API_CREDENTIALS)
|
||||||
|
for user_dict in resp.json()['results']:
|
||||||
|
try:
|
||||||
|
account = OIDCAccount.objects.get(user__email=user_dict['email'])
|
||||||
|
except OIDCAccount.DoesNotExist:
|
||||||
|
continue
|
||||||
|
for claim in cut_users.claim_mappings.all():
|
||||||
|
setattr(account.user, claim.attribute, user_dict.get(claim.claim))
|
||||||
|
try:
|
||||||
|
setattr(account.user.attributes, claim.attribute, user_dict.get(claim.claim))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
account.user.save()
|
||||||
|
|
||||||
# get new agents
|
# get new agents
|
||||||
cut_agents = OIDCProvider.objects.get(name='cut-agents')
|
cut_agents = OIDCProvider.objects.get(name='cut-agents')
|
||||||
|
|
||||||
|
|
Reference in New Issue