Skip to content

Commit 0c918e3

Browse files
author
Gonchik Tsymzhitov
committed
Add example to cleanup of inactive users from project roles
1 parent 229529f commit 0c918e3

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from atlassian import Jira
2+
import logging
3+
4+
"""
5+
That example related to the cleanup inactive users from project role configurations
6+
"""
7+
8+
logging.basicConfig(level=logging.ERROR)
9+
10+
jira = Jira(url="JIRA_URL", username="ATLASSIAN_USER", password="ATLASSIAN_PASSWORD")
11+
12+
13+
# Ger all role ids from Jira
14+
role_ids = []
15+
roles = jira.get_all_global_project_roles()
16+
for role in roles:
17+
role_ids.append(role.get("id"))
18+
19+
projects = jira.get_all_projects(included_archived=True)
20+
21+
for project in projects:
22+
project_key = project.get("key")
23+
print("Start review project {}".format(project_key))
24+
for role_id in role_ids:
25+
actors = jira.get_project_actors_for_role_project(project_key, role_id)
26+
for actor in actors:
27+
if actor["type"] == "atlassian-user-role-actor":
28+
username = actor["name"]
29+
if username is None:
30+
continue
31+
answer = jira.user(username)
32+
if answer.get("errorMessages") or (not answer.get("active")):
33+
print("Removing from project permissions {}".format(username))
34+
jira.delete_project_actors(project_key, role_id=role_id, actor=username, actor_type="user")

tests/mockup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def request_mockup(*args, **kwargs):
1919
url = kwargs["url"]
2020
if not url.startswith(SERVER + "/"):
2121
raise ValueError("URL [{}] does not start with [{}/].".format(url, SERVER))
22-
parts = url[len(SERVER) + 1:].split("?")
22+
parts = url[len(SERVER) + 1 :].split("?")
2323
url = parts[0]
2424
response_key = parts[1] if len(parts) > 1 else None
2525
if kwargs["data"] is not None:

0 commit comments

Comments
 (0)