Merge "Abstract Hard-Coded URLs to Config File"
[pharos-tools.git] / dashboard / src / account / tasks.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 from celery import shared_task
12 from django.contrib.auth.models import User
13 from jira import JIRAError
14
15 from account.jira_util import get_jira
16
17
18 @shared_task
19 def sync_jira_accounts():
20     users = User.objects.all()
21     for user in users:
22         jira = get_jira(user)
23         try:
24             user_dict = jira.myself()
25         except JIRAError:
26             # User can be anonymous (local django admin account)
27             continue
28         user.email = user_dict['emailAddress']
29         user.userprofile.url = user_dict['self']
30         user.userprofile.full_name = user_dict['displayName']
31         print(user_dict)
32
33         user.userprofile.save()
34         user.save()