Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profile Images in TFS 2012

Tags:

tfs

Is there a way to change users profile images as an administrator. At our company we have a central repository of everyone's images that we want to use on TFS Web Portal for their profiles. I know everyone can do it individually but can it be done globally for everyone?

like image 641
Lukasz Avatar asked Oct 05 '22 15:10

Lukasz


1 Answers

TL/DR

I've submitted a patch to the ALM Rangers Team Tools Quick Response Sample which provides profile image functionality to any TFS Administrator.


The Details

Official answer: no. Not in the current version of the platform, it is being considered for a future release.

Real answer, it can be done with api trickery. It is still unsupported though. I'm working on a command line tool that does just that. I can probably share it after the holidays. Should you need it earlier, open the webaccess dll's in reflector.net and you'll be able to find the code in question.

The profile image is basically an extended property of the identity object of the user.

The important lines are:

            _identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Data", imageData); /* byte[] containing 90x90px png */
            _identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Type", "image/png");
            _identity.SetProperty("Microsoft.TeamFoundation.Identity.Image.Id", Guid.NewGuid().ToByteArray());
            _identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.Data", null);
            _identity.SetProperty("Microsoft.TeamFoundation.Identity.CandidateImage.UploadDate", null);
            UpdateIdentity();

Code to update identity:

    private static void UpdateIdentity()
    {
        try
        {
            _service.UpdateExtendedProperties(_identity);
            _service.RefreshIdentity(_identity.Descriptor);
        }
        catch (PropertyServiceException)
        {
            //swallow;
        }
    }

Code to retrieve the identity service and identity:

        var server = TfsConfigurationServerFactory.GetConfigurationServer(new Uri("http://localhost:8080/tfs"));
        server.ClientCredentials = new TfsClientCredentials();
        server.ClientCredentials = new TfsClientCredentials(new WindowsCredential(new NetworkCredential(connectUser, password)));
        server.Authenticate();

        _service = server.GetService<IIdentityManagementService2>();

        var identities = _service.ReadIdentities(IdentitySearchFactor.AccountName,
                                                new[] {userToSetImageOn}, MembershipQuery.None, ReadIdentityOptions.None);
like image 78
jessehouwing Avatar answered Oct 10 '22 02:10

jessehouwing