Forums

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

Never logged in user with their login created date through script runner for confluence

Ankit Choudhary January 2, 2024

Hi,

I have a code to fetch the never logged in user. Can i get the login created date also?Please help to find the code for the functionality mentioned



import com.onresolve.scriptrunner.parameters.annotation.GroupPicker
import com.atlassian.crowd.embedded.api.Group
import com.onresolve.scriptrunner.parameters.annotation.*
import com.onresolve.scriptrunner.parameters.annotation.meta.*
import java.lang.String
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.ConfluenceUserImpl
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.GroupManager
import com.atlassian.confluence.security.PermissionManager
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.confluence.user.*
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.UserManager
import com.atlassian.user.security.password.Credential
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.rpc.soap.services.SpacesSoapService
import java.io.*
import groovy.lang.*

@GroupPicker(label = 'User group', description = 'The group of users to check (e.g. "confluence-users")')
Group selectedUserGroup

def groupManager = ComponentLocator.getComponent(GroupManager)
def loginManager = ComponentLocator.getComponent(LoginManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)

def userGroup = selectedUserGroup ? groupManager.getGroup(selectedUserGroup.name) : groupManager.getGroup('groupname')

// Get all users from the selected user group
def users = userAccessor.getMembers(userGroup).asList()

// Create an HTML table to display the user information
def htmlTable = "<table><tr><th>User</th><th>Last Login Date</th></tr>"

users.each { user ->
    def lastLoginInfo = loginManager.getLoginInfo(user)
    

    if (!lastLoginInfo?.lastSuccessfulLoginDate &&  !userAccessor.isDeactivated(user)) {
        // User has never logged in and is active
        htmlTable += "<tr><td>${user.name}</td><td>Never logged in</td></tr>"
    }
}

htmlTable += "</table>"

return htmlTable

1 answer

1 accepted

1 vote
Answer accepted
Ravina
Community Champion
January 5, 2024

Hi @Ankit Choudhary I would recommend to use the sql query to be used in the script to get the last login and account created data for the users in Confluence

Capture 2024-01-05 at 15.41.46.png

I am not able to put this sql query in the comment as getting the HTML error so please check the attached screenshot for the sql query and sucessdate as per your requirement.

 

Thanks

Ravina

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events