Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove users from all groups After user account is disabled.

Pavan kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 19, 2024

Hi team, 

 

Upon a user leaving the organization, their access to JIRA and Confluence is revoked through SCIM, but the permission groups they were added to remain intact. We are manually removing users from permission groups upon deactivation. Can we automate this process to remove users from other permission groups when they are deactivated?

 

Regards:

Pavan.

1 answer

0 votes
Rudy Holtkamp
Community Champion
March 19, 2024

Hi Pavan,

You should be able to write a script which:

  1. get all groups for the user that is leaving
  2. delete the user from each group.

With this REST API you can delete the user from a group, but if you use Python you can use the atlassian library and create a script like:

from atlassian import Jira

# Jira API credentials and base URL
USERNAME = 'your_username'
PASSWORD = 'your_api_token'
JIRA_URL = 'https://your_jira_instance_url.atlassian.net'

# Function to fetch user groups
def get_user_groups(username):
jira = Jira(url=JIRA_URL, username=USERNAME, password=PASSWORD)
groups = jira.user_groups(username)
return groups

# Function to remove user from groups
def remove_user_from_groups(username, groups):
jira = Jira(url=JIRA_URL, username=USERNAME, password=PASSWORD)
for group in groups:
jira.remove_user_from_group(group, username)
print(f"User {username} removed from group: {group}")

# Main function
def main():
# Input username
username = input("Enter the username: ")

# Fetch user groups
user_groups = get_user_groups(username)
if user_groups:
print(f"User {username} belongs to the following groups: {', '.join(user_groups)}")

# Remove user from groups
remove_user_from_groups(username, user_groups)

if __name__ == "__main__":
main()

Good luck 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events