Hi All,
is it possible to get the list of inactive users of JIRA by jelly or groovy?
Note, I do not have access to DB so SQL is not possible.
Thanks in advance,
Rumi
Yes.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserManager UserManager userManager = ComponentAccessor.getUserManager() userManager.getUsers().findAll{user -> !user.isActive()}.each { user -> //... }
Hello Henning,
Can we get list of inactive users for specific time, like I need list of users who are inactive from last 30 days?
Regards,
Hi,
if you define inactive as "not logged in" you can use something like this.
import com.atlassian.jira.component.ComponentAccessor def crowdService = ComponentAccessor.crowdService def ofBizUserDao = ComponentAccessor.getComponent(OfBizUserDao) def userUtil = ComponentAccessor.userUtil def dateLimit = (new Date()) - 30 userUtil.getUsers().findAll { it.isActive() }.each { def user = crowdService.getUserWithAttributes(it.getName()) def lastLoginMillis = user.getValue('login.lastLoginMillis') if (!lastLoginMillis?.isNumber()) { def tu = ofBizUserDao.findByName(user.directoryId, user.name) lastLoginMillis = tu.getCreatedDate()?.time } if (lastLoginMillis) { def d = new Date(Long.parseLong(lastLoginMillis)) if (d.before(dateLimit)) { // not logged in for 30 days... } } }
If the user never was logged in, this uses the created date for calculating the time of "inactivity".
Henning
Groovy error.JPG
I do not have Atlassian crowd integrated , can I still use this script ? or is there anyway to generate the list of inactive users in my jira without crowd services.
Thanks
Ramji
The script doesn't need an explicit crowd integration, it's meant for a pure Jira installation. The CrowdService class used by the script is part of Jira.
@Henning Tietgens
could you please help me , how to add an attachment to the mail?
we are using below script for sending a mail:
import com.atlassian.mail.Emailimport com.atlassian.mail.server.SMTPMailServerimport com.atlassian.jira.component.ComponentAccessor
def emailSubject="test mail"def emailBody="test mail body"def emailAddress="yampalla.srinivasareddy@gmail.com"SMTPMailServer mailServer=ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if(mailServer){Email email=new Email(emailAddress)email.setSubject(emailSubject)email.setBody(emailBody)mailServer.send(email)}
Try something like this
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.mail.Emailimport com.atlassian.mail.MailExceptionimport com.atlassian.mail.MailFactoryimport com.atlassian.mail.queue.SingleMailQueueItemimport javax.activation.DataHandlerimport javax.mail.BodyPartimport javax.mail.Multipartimport javax.mail.internet.MimeBodyPartimport javax.mail.internet.MimeMultipartimport javax.mail.util.ByteArrayDataSourceMultipart mp = new MimeMultipart("mixed")BodyPart attPart = new MimeBodyPart()// take care to set correct mime type for the attachmentByteArrayDataSource attBds = new ByteArrayDataSource(data, 'text/plain; charset=utf-8')attPart.setDataHandler(new DataHandler(attBds))attPart.setFileName(attachmentFileName)mp.addBodyPart(attPart)def mailServerManager = ComponentAccessor.getMailServerManager()def mailServer = mailServerManager.getDefaultSMTPMailServer()if (mailServer && !MailFactory.settings.isSendingDisabled()) { Email email = new Email(emailTo, emailCC, emailBCC) email.setMultipart(mp) email.setFrom(mailServer.getDefaultFrom()) email.setSubject(config.emailSubject) email.setMimeType(config.emailMimeType) email.setBody(config.emailBody)try { SingleMailQueueItem item = new SingleMailQueueItem(email) ComponentAccessor.getMailQueue().addItem(item) }catch (MailException e) { log.error("Error sending email", e) }} else { log.warn("No mail server or sending disabled.")}
Here is a Jira cloud addon developed by my company that allows you to search, filter and bulk delete users:https://marketplace.atlassian.com/apps/1221764/user-management-by-toros
In addition, it allows you to search for inactive users (users who haven't login in a while) and perform some bulk operation.
It looks like you're new here. Sign in or register to get started.