Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can my Stash Plugin display the same avatars as other parts of Stash?

Graham Lea March 6, 2014

Writing a Stash plugin and I want to display avatars for users.

In core Stash pages, I can see there are lots of AUI classes and a 'data-username' attribute around the gravatar images, but I also know that the location of the gravatar server can be modified and that custom, local avatars are in progress.

How can my plugin generate the same avatars that Stash will use for the same users / email?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
cofarrell
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 7, 2014

Hi Graham,

If you can try using the stash.widget.avatar soy function:

{namespace stash.widget}

/**
 * @param size either 'xsmall', 'small', 'medium', 'large', 'xlarge', 'xxlarge' or 'xxxlarge'
 * @param person a StashUser or Person
 * @param? tooltip
 * @param? extraClasses
 * @param? imageClasses
 * @param? badgeContent extra HTML for badge
 * @param? hideBadge if true, the badge is hidden (but html is still present in the dom)
 * @param? id
 */
{template .avatar}
...
{/template}

An example in the wild.

{call stash.widget.avatar}
    {param size: 'large' /}
    {param person: $user /}
{/call}

Technically it's deferring to a Stash-specific soy function called avatarUrl() which takes a Person/StashUser java object ($user in this example). It's not something you can generate purely on the client-side (just as a warning).

Cheers,

Charles

PS. My usual disclaimer, this isn't technically public API and as such is something that may change in future versions (although I suspect it won't). We do plan on expanding and documenting our JS/Soy public API at some stage.

Graham Lea March 7, 2014

Thanks for the answer, Charles. Doesn't seem to be working in my environment, though. I get a SoyTofuException: "Attempting to render undefined template 'stash.widget.avatar'."

I also added the AvatarEnricher I saw in stash-suggest-reviewers' atlassian-plugin.xml file (I assume that's necessary?), but that didn't fix the problem above.

Stash version is 2.10.2 (2010002). Any ideas?

Cheers,

Graham.

cofarrell
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 7, 2014

Hi Graham,

What does your atlassian-plugin.xml look like? Does adding the following fix that error?

<dependency>com.atlassian.stash.stash-web-plugin:avatar</dependency>

Ignore the AvatarEnricher unless you want to add the avatarUrls to Stash REST objects that you are returning.

Cheers,

Charles

Graham Lea March 8, 2014

Thanks, Charles. That dependency was the missing link.

Two trailing questions:

1) Is there a similar soy template for creating a link to a user profile based off a StashUser?

2) I know you're probably a bit removed from this, but is my use of something that "isn't technically public API" likely to prevent my plugin from being approved fo the marketplace?

Cheers,

Graham.

cofarrell
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 9, 2014

1. {call stash.widget.avatarWithName}{param link: true /}...{/call}

2. I'm not sure what level of approval Marketplace do, but fortunately or unfortunately it's got nothing to do with API compatability.

While I know we need to improve our API documentation, my advice is to have a copy of the Stash source lying around so you can grep for examples. That's what I usually do. :)

Charles

TAGS
AUG Leaders

Atlassian Community Events