SPWebPartManager to hide webparts per user - sharepoint-2010

Can I use SPWebPartManager to hide Web Parts per user programmatically?
Such as: Get the SPWebPartManager instance, iterate through the Web Parts, and set visible = false depending on the user.
I heard from somewhere there when you set webpart.visible = false this sets this for all the users, is this true?

You need to open the Web Part in the user scope in order to update user specific properties. Use the PersonalizationScope Enumeration to open the SPLimitedWebPartManager accordingly:
SPWeb web = // ...
using (SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(
"<path to page>",
PersonalizationScope.User))
{
WebPart wp = mgr.WebParts[<ID of the web part to update>];
wp.Hidden = true; // hide the web part.
mgr.SaveChanges(wp);
}
Note: In order to update a peropery in the PersonalizationScope.User the property needs to be marked as personal web part storage ([WebPartStorage(Storage = Storage.Personal)]):
MSDN description for the User PersonalizationScope scope:
When referring to the scope on the WebPartManagercontrol, User scope means that personalization data that is user-specific, as well as personalization data that applies to all users, is loaded for all personalizable controls on a page. Only personalization data that is user-specific can be saved on the page.
When referring to the scope associated with a Web Parts control property, User scope indicates that the property can only load and store data applicable to all users when running on a page in Shared scope. However, when the property's control is running on a page in User scope, the property's per-user and all-user data will be loaded and merged. In this case, though, only per-user data will be saved when a page is running in User scope.

Related

how to prevent exposure of Notes views from browser

How can I prevent that the default views are exposed in my Domino application? is there a special $$form for that?
It seems my application now and looses it web launch property
You can hide all views from web. If it's an XPages application, all views are accessed server-side so never need to be accessible from browser.
You can create a form called $$ViewTemplateDefault and leave it empty. All views opened from web (with for example the command ?OpenView) will then just display an empty page.
There are a couple ways to do that. One is with ACL entries. The other (which you refer to) is to create a form called $$View Template for [View name] For example, if your view is called All documents, the form would be called $$View Template for All Documents. Just leave the form blank, or put some static text on it ("Access Denied" perhaps.) You should also have one called $$ViewTemplateDefault which will cover any views you haven't explicitly protected.

SAPUI5 sap.ui.table.Table

is there a way to save the columnsettings of a SAPUI5-Table?
if the user logout and relog again the table properties should be saved.
what i have to do is to save the column settings which can be manipulated by user interaction.
Property: showColumnVisibilityMenu:true
i'm using sap.ui.table.Table
var oTable = new sap.ui.table.Table({
title: "Table Example",
selectionMode: sap.ui.table.SelectionMode.Single,
showColumnVisibilityMenu:true, // those settings should be saved
});
actually i've found an example here to preview the selection of the columns (hide or show):
http://jsbin.com/ceduc/1/edit?html,js,output
So when the user decides to hide the column "Key1 Label" (figure below) and want to logout and relog again, the column shouldn't be visible. the configuration of the table columns should be saved for a user. how to do that?
It depends on how exactly do you want to persist the view settings and on what backend you have.
If you have an ABAP backend which has the unified shell services (delivered as part of Fiori), then you can use the standard Personalization controller / services to persist the settings. See this demo, the UI5 documentation and the unified shell service docu.
If you have any other type of backend or you don't want to use the personalization services, then you should save the visibility of the columns inside a (dedicated) model. Then you can save the content of this model on your backend (by simply sending it to a dedicated REST service and persisting it e.g. in the database). When the user logs back in, you can read this model and simply restore it.
Another possibility would be to save it in the local storage of the browser. You still need the model from above, but instead of sending the data to the backend via AJAX, you simply save it to the local storage and load it from there when needed.
You can make use of SAP's standard Shell personalization Service.
Here is how I would do it.
Use Personalization Dialog (sap.m.P13nDialog) for managing Table's options
Get standard personalization service provider
var oProvider = sap.ushell.Container.getService("Personalization").getPersonalizer(oPersId);
Connect your table with personalization provider and activate
var oTablePersoController = new sap.m.TablePersoController({
table: oTable,
persoService: oProvider }).activate();
This will automatically take care of saving and retrieving variants/personalization.
Launch the Personalization Dialog upon user cliking the corresponding button
You may use sap.ui.table.TablePersoController for sap.ui.table.Table

How do I load a Sitecore sublayout automatically so that permissions are respected?

I've created a sublayout (usercontrol) with some simple html. I want to display this sublayout only if the user belongs to a certain role.
If I use the built in sitecore developer center to add the sublayout, I end up with something like
<sc:Sublayout runat="server"
RenderingID="{item guid here}"
Path="/layouts/sublayouts/someusercontrol.ascx"
ID="Sublayout1" placeholder="content"></sc:Sublayout>
Denying read permission for the sublayout used there has no affect (I assume it's getting loaded because the file path is there right? ). If I take the Path out I get nothing regardless of current user role.
I don't want to manually check if the current user is in the right role from the codebehind. What markup do I use to get the sublayout to consider the user's permissions and determine visibility?
I don't think it's possible to control sublayout visibility based on a user role in markup. If you dynamically added this sublayout to a placeholder, you could use conditional rendering ("Personalize" button in 6.5) to accomplish this, hiding the component unless the user is a member of a specific role.

Disable Links to My Site profiles in Sharepoint 2010

I would like to utilize some of the social collaboration features in Sharepoint 2010, such as the Noteboard webpart and tagging, but do not want to use the My Site profile pages.
I have already built a custom control that redirects from the userdisp.aspx page to a custom user profile page. I would like to continue to use that custom profile page. However, it seems like user profile links that are generated by the Noteboard webpart, for example, go directly to the /Sites/MySites/person.aspx page without being routed through the /_layouts/userdisp.aspx page. So my profile redirect control doesn't catch it.
In Sharepoint Central Admin, under Manage Service Applications > User Profile Service Application > Manage User Permissions, I have only checked the box for "Use Social Features", not "Create Personal Site," so I am not sure why the profile page is not linking to the old userdisp.aspx page.
Is it possible to redirect these links back to the userdisp.aspx page?
It appears to be hardcoded into the webpart.
I looked at Microsoft.SharePoint.Portal.WebControls.SocialCommentControl and the link comes from UserProfile.PublicUrl, which is defined as:
public override Uri PublicUrl
{
get
{
string userProfileUrl = UserProfileGlobal.GetUserProfileURL(
this.m_objManager.UserProfileApplicationProxy,
this.m_objManager.PartitionID,
"?accountname=",
this.m_UserProfileFields["AccountName"].ToString());
if (!string.IsNullOrEmpty(userProfileUrl))
return new Uri(userProfileUrl);
else
return (Uri) null;
}
}
which eventually calls:
internal static string GetUserProfileURL(string profileWebUrl, string strIdentifier, string strValue)
{
if (string.IsNullOrEmpty(profileWebUrl))
return (string) null;
else
return PersonalSpaceGlobal.EnsureTrailingSlash(profileWebUrl)
+ "Person.aspx"
+ strIdentifier
+ (strIdentifier.Equals("?accountname=", StringComparison.OrdinalIgnoreCase)
? SPHttpUtility.UrlKeyValueEncode(strValue).Replace(":", "%3A")
: SPHttpUtility.UrlKeyValueEncode(strValue));
}
I can think of two workarounds:
Add jQuery to your page to change the URL (selector = span.socialcomment-username > a)
Create your own webpart containing a custom control that inherits from SocialCommentControl, which overrides RenderComment.
Overriding RenderComment is probably going to be messy. You will need to copy the decompiled code for the method just to change the following into your own code:
SocialCommentControl._GetProperty(
comment,
SocialCommentControl.SocialCommentProperty.PublicPage)
Hopefully, there are no internal method calls within RenderComment's 67 lines of code. Otherwise, it is going to be a lot more difficult to implement. It would be a lot easier if you could simply override _GetProperty, but unfortunately, it is a static method.
All of that to say, I would probably recommend the jQuery option over extending SocialCommentControl.

Plone make login mandatory on every page but main page

A customer wants to have its Plone site behave like this:
the main page can be seen by anonymous users
you have to be registered and authenticated to see any other page
the site is open for registration, so the forms to authenticate and register should also be made visible by anonymous
How one can approach this?
Is there a way to hook a python script/class/method/function to any request made by the user? Overriding the main_template.pt and adding a TAL call to a method that does these checks would be enough?
The tricky part is that even if the anonymous can only visit the main page, the main page in itself is made up of other content types which should be only viewed by authenticated users (by their restrictions, not because of workflow).
I ruled out, maybe a mistake?, workflow because then everything should be made private but still the global_nav is made out of folders which, if the workflow approach was taken, should be private/non-viewable by anonymous.
Cheers,
Try this:
add a state internally published to your workflow
copy permissions configuration from the "public" state into the new state and than remove the "View" permission from the Anonymous User (maintain the 'Access content information', that's the key). Then add all needed transitions.
put your home page in "public" state
put everything else in 'internally published' state
This should work because if you link content's information in the homepage, this will work, but if someone try to access a content he will miss the "view" permission and will be redirected to the login.