Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.atlassian.crowd.embedded.api.User
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.component.ComponentAccessor
- import com.atlassian.jira.issue.search.managers.SearchHandlerManager
- import com.atlassian.jira.issue.subscription.SubscriptionManager
- import org.ofbiz.core.entity.GenericValue
- class RemoveSubscriptionsForInactiveUsersClass {
- def String doRun() {
- StringBuffer report = new StringBuffer()
- //Remove subscription created by users who have been inactivated
- SubscriptionManager manager = ComponentAccessor.getSubscriptionManager()
- //Upload all the subscriptions within a set (no double on the username)
- Set<String> users = new TreeSet<String>()
- manager.getAllSubscriptions().each { GenericValue subscription ->
- String uname = subscription.getString("username")
- if (uname) {
- users.add(uname)
- }
- }
- //And compare the user list with the user database. If one of them is inactivated, them remove the subscription(s)
- users.each { String username ->
- report.append "${user.name} have subscription(s), check the user status\n"
- User user = ComponentAccessor.getUserManager().getUser(username)
- if (!user.active) {
- report.append "Remove subscription(s) for the inactivated user ${user.displayName} (Username: ${user.name})"
- manager.deleteSubscriptionsForUser(user)
- }
- }
- }
- }
- new RemoveSubscriptionsForInactiveUsersClass().doRun()
Advertisement
Add Comment
Please, Sign In to add comment