Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to create a Web Part that will conditionally display its contents if the current user has permission to see a specific user profile property. Here's what I've got so far. It seems that I can use the ProfileSubtypeProperty privacy settings, but I'm not sure what to do. I'd like to hide the content when either 1) the user cannot override the privacy settings and the default privacy setting doesn't allow the current user to view the profile property or 2) the user can override the privacy settings and has done so so that the current user can't see the profile property.

The first part, I think I can figure out using UserOverridePrivacy and DefaultPrivacy. The second part is what I need help with. How can I check to see what whether or not the property should be visible?

This stems from an earlier question I'd asked.

Control code:

[ParseChildren(true)]
[PersistChildren(false)]
[ToolboxItemAttribute(false)]
public class UppvWebPart : WebPart
{
    public class UppvWebPartTemplate : WebControl, INamingContainer
    {
        protected override void Render(HtmlTextWriter writer)
        {
            this.RenderContents(writer);
        }
    }

    protected override void CreateChildControls()
    {
        String accountName = HttpContext.Current.Request["accountname"];
        if (UvvpWebTemplate != null && PropertyName != null && accountName != null)
        {
            SPWeb thisWeb = SPContext.Current.Web;
            SPServiceContext context = SPServiceContext.GetContext(thisWeb.Site);
            UserProfileConfigManager upcm = new UserProfileConfigManager(context);
            ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
            UserProfileManager upm = new UserProfileManager(context);

            if (upm.UserExists(accountName))
            {
                UserProfile userProfile = upm.GetUserProfile(accountName);

            ProfileSubtypeProperty psp = userProfile.Properties.GetPropertyByName(PropertyName);
            if( /* what to do with psp? */)
            {
                ProfileValueCollectionBase pv = userProfile.GetProfileValueCollection(PropertyName);

                if (pv != null)
                {                        
                    foreach (String v in pv)
                    {
                        HttpContext.Current.Response.Output.WriteLine("<p>{0}</p>", v);
                    }

                    Control container = new Control();
                    this.Controls.Add(container);
                    UvvpWebTemplate.InstantiateIn(container);
                }
            }
            }
        }
    }

    public virtual String PropertyName
    {
        set;
        get;
    }

    [Browsable(false)]
    [DefaultValue(null)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    [TemplateContainer(typeof(UppvWebPartTemplate))]
    public virtual ITemplate UvvpWebTemplate
    {
        set;
        get;
    }
}

And here is the usage:

<UppvWebPart:UppvWebPart PropertyName="Hobbies" runat="server" Description="My WebPart" Title="UppvWebPart" __MarkupType="vsattributemarkup" __WebPartId="{339ea49b-f2b0-4bd6-a029-73ead84e4915}" WebPart="true" __designer:IsClosed="false" id="UppvWebPart1">
    <UvvpWebTemplate><div id="Bam1Div" runat="server">Show the property!</div></UvvpWebTemplate>
</UppvWebPart:UppvWebPart>
share|improve this question
    
The comment /* what to do with psp */ above in part could be ! psp.UserOverridePrivacy && psp.DefaultPrivacy == Privacy.Public || psp.UserOverridePrivacy && /* ??? */, but –  Don 01001100 Jan 5 '12 at 20:33

1 Answer 1

from what I can see, the DefaultPrivacy property is the only thing you should need to check. Provided this is at the right level to display then you don't need to do any alternative checks if the UserOverridePrivacy is set. If I'm completely honest, I haven't tried this, but looking through the object model the DefaultPrivacy property appears to be the only property to hold any privacy settings for the user profile property. I'd be interested to know whether you've managed to sort this out...

share|improve this answer
    
We've decided not to use SharePoint for this project, so no sorting this one out. Thanks for the reply, though. –  Don 01001100 May 15 '12 at 13:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.