Import avatars

Stephen Stephen March 23, 2012

Is there anyway to import user avatars via script or other means.

We already have everyone's pictures in active directory, and we are using jira delegated authentication.

I'd be willing to write a script that places a JPG on the server and updates SQL if that's possible.

7 answers

3 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2014

6.3 has a configurable URL for gravatars. Since that release, I've dropped the rewrite rule method and just point to an app that can look up the picture from the mail md5 digest. This could be written as a jira plugin even.

The other reason not to use rewrite rules anymore, is that 6.3 inlines the avatars if they are local, and also latest greenhopper has "first initial" default avatars, which don't play nice with the rewrites.

Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2014

Thanks, that you pointed this important enterprise feature out - missed it from JIRA 6.3 release notes. Now with help of Confluence Avatar Service we can achieve consistent avatars in Atlassian stack.

2 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

IMHO there is a better alternative, which is to use url redirection to redirect requests for jira avatar images to whatever servlet etc you have that provides images given a user name.

Example of apache rewrite rules:

RewriteRule /jira/secure/useravatar\?size=small&userId=(.*)\& /picture/viewPhoto/$1?width=16&height=16 [L,R]
RewriteRule /jira/secure/useravatar\?.*?userId=(\S+?)\b /picture/viewPhoto/$1?width=48&height=48 [L,R]
RewriteRule /jira/secure/useravatar\?.*?ownerId=(\S+?)\b /picture/viewPhoto/$1?width=48&height=48 [L,R]
RewriteRule /jira/secure/project/AvatarPicker /res/avatarpicker_replacement.htm

Advantage of this is you do not need to maintain a process to keep the jira avatars up to date. Minor changes were required to some jira templates to ensure the userId was always present in the url.

I use the same thing for confluence, fisheye etc, works well.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

Hi, yes it is. But could also be done with urlrewrite.xml with vanilla jira.

Darren Pegg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

Hi Jamie,

is this written within the HTTPD file? You mention apache...

Thanks


Darren

Darren Pegg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

Brilliant - Thanks :-)

1 vote
Dmitri Barski July 20, 2014

I have successfully tested the following script (it assumes the avatars are on the hard drive in d:\temp\avatars and it also assumes the file names are "username.jpg"...the "export from Active directory" part is solved for me by a simple Powershell script and it takes care of correct naming for the files):

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.avatar.Selection;
import java.io.FileInputStream;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

def avaMan = ComponentAccessor.getAvatarManager() // the Avatar Manager is needed to create avatars from files
def uMan = ComponentAccessor.getUserManager() // needed to get ApplicationUser objects 
def avaSe = ComponentAccessor.getAvatarService() // AvatarService associates avatars with users
def setter = uMan.getUserByKey("bigadmin"); // put an administrator ID here

def p = ~/.*\.jpg/;
def d = new File( 'd:\\temp\\avatars' ); // can be whatever path your avatar files are at
d.eachFileMatch(p) {
    f ->
        def user = f.name.replaceFirst(~/\.[^\.]+$/, '');
        def owner = uMan.getUserByKey(user);
        if (!avaSe.hasCustomUserAvatar(setter, user)) { // we don't want to overwrite avatars for the users who already have custom avatars

            def avaIS = new FileInputStream (f);
           
            def img = ImageIO.read(f);
            def width = img.getWidth();
            def height = img.getHeight();
            def midX = width/2;
            def midY = height/2;
            def sz = (width < height)? height : width;
           
            def ava = avaMan.create(user+'_real.jpg', 'image/jpeg', owner, avaIS, new Selection(Math.max((int)(midX - sz/2),0),Math.max((int)(midY - sz/2),0), sz, sz)); // not an ideal solution, but better than nothing; automatic cropping is a difficult matter anyway

            avaSe.setCustomUserAvatar(setter, owner, ava.getId());   
        }
        f.delete() // cleanup the avatar set
}

0 votes
Daniel Bajrak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2014

Hi,

You can use plugin Active Directory Integration, which can do this in very easy way. You need to add configuration to connect with Active Directory or Ldap server, then choose import pictures and that's all that you need to do.

https://marketplace.atlassian.com/plugins/com.intenso.jira.plugins.ad-integration-manager

and plugin's documentation: http://plugins.intenso.pl/display/PLUG/Active%20Directory%20Integration%20with%20JIRA

0 votes
Roy Moshkovitz June 1, 2012

Hi Septa,

Can you please share some java/servlet code?

And also, what do you do when the original Photo Servelet does not contain info like ownerId or userId? how do you know what user is it?

Thanks,

Roy

0 votes
Septa Cahyadiputra
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

Hi Stephen,

You might want to refer to our bug report here:

https://jira.atlassian.com/browse/CONF-22298

There is a SQL script that might help you out on this issue. Hope it helps.

Cheers,

Septa Cahyadiputra

0 votes
SimonS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2012

Hey Stephen,

It should be possible via scripting - you have access to the JIRA database and AD avatars - it should only be a metter of creating the appropriate query or script.

I'll leave it to a developer to fill in the details of what you may need to do, though.

-Simon

Suggest an answer

Log in or Sign up to answer