Liferay site specific property - liferay

I have a requirement where I need to define a site specific property and if the property is present perform certain action.
I do not want to use portal-ext.properties as that is portal wide, what i need is a property that is specific to site.
Any pointers?

If you need the properties in some configuration file - you can still use portal-ext.properties and add some site specific id to the key:
my.property.12048 = The setting for the group (site) with id 12048
You can access these from code with PropsUtil:
String propertyValue = PropsUtil.get("my.property" + group.getGroupId());
(You could use other identifiers like the friendly URL as well).
If you like to have an editable value in the UI - you can declare a custom field for a site in the control panel and set the value for each site in the site administration. To access that value from code:
String propertyValue = (String) group.getExpandoBridge().getAttribute("myCustomFieldName");

Related

Is there any way to add new field to Kentico Kontent content item Meta tab

So what I am basically trying to do, is to have the ability to add custom field(e.g. Secondary URL) to Content item Meta Tab, so that the user can set it manually on demand. Reading docs did not bring any result
On the attached screenshot, you can see Path, Navigation title fields, so I need to add additional one
to be able to modify the content type - in your case adding a new field - it is required to have the proper permissions via assigned roles. More specifically, you need to have permission to modify content.
Content modeling could be done via UI - see Content modeling tutorial, in your case it is Adding an element into a content group "Metadata". You also can use REST Management API for that.

Retrieving User Name in Sharepoint?

How does Sharepoint retrieve the user's actual name as displayed in the top right corner? e.g Welcome John Smith
I need to call this name as a variable or parameter on custom code in the XSL editor but I can't figure out how I can retrieve it, is it a global variable?
You can get a user's account name using the server variable LOGON_USER. However, this doesn't return a user's Display name.
I was able to get something working which a combination of web parts to display their name:
Add a UserContextFilterWebPart (you may need to enable this web part in the web part gallery).
Add a DataView webpart which queries the GetUserInfo method (part of the UserGroup.asmx web service).
a. Click "Connect to a web service..." in the Data Source Library pane under XML Web Services
b. Enter the Service description location (the URL to the UserGroup web service). Ex: http://server/sites/SiteCollection/SubSite/_vti_bin/UserGroup.asmx?WSDL
c. Click Connect (or reconnect)
d. Choose GetUserInfo for the Operation dropdown (the other dropdowns should be ok)
e. Modify the userLoginName parameter and check the box to allow the value to be set via web part connection. I also added a default value to test (ex: domain\login).
f. Click OK.
g. Click on the data source and click Show Data
h. Choose the columns you need and then drag them onto the page
Connect them together using web part connections (UserContext provided to the DataView).
If you want to use SPServices (which is great, btw):
function getCurrentUsersName(){
var firstName = $().SPServices.SPGetCurrentUser({
fieldName: "FirstName",
debug: false
});
return firstName;
}
function getCurrentUsersLastName(){
var lastName = $().SPServices.SPGetCurrentUser({
fieldName: "LastName",
debug: false
});
return lastName;
}
You can look up a host of other similar fieldnames here:
I believe it's coming in through NTLM Authentication/Active Directory. I ususally get login name DOMAIN/User in the HttpContext.Current.User.Identity.Name field, and then match against Active Directory and bring back the actual name of the user.
SPContext.Current.Web.CurrentUser.LoginName will give you the value for the login name of the current user, as displayed in the top right of a standard portal.
If you want to use this with XSLT, you need to find a way of assigning this to an XSL parameter value at run-time.

How to restrict SharePoint WSS3 users to edit only fields that are in their dedicated views

I have a list with the fields: Title, Client, Project, Description.
There is a view for analysts with the fields visible: Title, Project, Description.
All is fine so far as the analysts work with their views and not with the lists. But when they need to modify the records clicking on Edit, they see and able to modify the 'Client' field too.
How to prevent 'Client' field to be available for editing by the group? is there a way in WSS or I need to look for 3rd party list components?
All fields have a set of properties that determine their visibility in forms, such as "ShowInNewForm", "ShowInEditForm", and "ShowInDisplayForm". There's also some for the file dialog, the list settings page, and a few other places, but that's getting past it. Short answer, yes, you can make the field not show up in the edit form with WSS without needing any 3rd party components.
If you need a field that cannot be seen in the Edit Form by anyone (that is, no one should be able to have it in their form), then you need to modify "ShowInEditForm" to be true. This can't be modified directly through the SharePoint UI, but it is extremely simple using the object model.
If you need certain people to edit it at some point through the SharePoint UI, then you'll instead have to create a custom edit form. That's a bit more complex, so I'll hold off on providing that instruction unless you state you need to go down that route (or someone else passes by this answer and requests it). Nevertheless, it is fully possible with WSS 3.0.
EDIT
If you know already know how to insert inline C# code into an ASPX page, you can perform this very simply using SharePoint Designer. First, follow the instructions from this article, especially make sure you don't delete the default list form web part. Now, in the custom list form you added, make it include every field which anyone will be capable of editing. The last step is to make the form hide those fields for certain people. Let's default them to Visible=false, and flip this switch if the user is allowed them. You can do this either by checking if the current user is part of specified groups, or by checking if the user has a certain permission level only held by people of those groups. You'll basically write some code like the following, I'll use checking for a specified group as the example.
using (SPWeb web = this.Web)
{
SPUser currUser = web.CurrentUser;
string[] listOfGroups = { "Group1Name", "Group2Name", "Group3Name" };
foreach (string groupName in listOfGroups)
{
if (currUser.Groups.Contains(groupName))
{
//Repeat this for each Control, refer to them by their ID. For example, this is for a control with the ID txtTitle.
txtTitle.Visible = true;
}
}
}
If you don't know inline code, you'll have to write a custom ASPX page with a code-behind. Copy EditForm.aspx into a new file - you should do this after setting up a Custom List Form as per the article. You could also build a new ASPX page from scratch, but make sure you include all of the necessary Content placeholders for SharePoint pages. Now, the page currently inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. We need to create custom code that inherits from that class, and change the page to inherit that new custom code instead. In the custom code, override one of the OnLoad or OnInit methods, and include your check for the user's permissions there as detailed earlier. Compile the code, deploy it to your SharePoint server, and it should be functional.
If you want to set fields hidden or display them in new form or edit form page of the list...
Go to the list settings.
In Advanced Settings, enable "Allow management of content types"
By doing so, you will get a List name Link on the List Setting Page.
Open the link and select the fields that you want to hide or uhide using add or remove option.
After saving this, again disable "Allow management of content types" in Advanced Setting...
Thats it :)))

Drupal show / hide fields in view

I would like to show / hide certain fields in my Drupal view accordingly to the user role.
Provided I can only have this view to work with, how can I achieve this programmatically or there's some settings that I am not aware of in Drupal.
P/S: I am aware of the access settings under basic settings in View but that would restrict access to the whole view, not field level.
You can create two identical Displays (within the same view) and override the field settings and access settings in each of them. For example, in the first display show the fields you only want a certain role to see, and set the access control setting to that role. In the second display, remove the unwanted fields and set the access control to the corresponding role.
Start by creating the most restrictive display first and then the least restrictive one.
I liked this answer, but in my case the field is dependent on the argument and I would need to create a new display for each argument (which isn't practical).
I installed the Views Custom Field module and used this code for the field:
<?php
if(user_access("some permission string here"))
{
print "Your field value here";
}
?>
Click advanced, theeming, find the field and make a _.tpl.php file for it, then in the file you will see:
print $output;
Change this to:
if (user_access('administer nodes')) {
print $output;
}
Or whatever the permission is you are checking against.
I think you have to try module Field Permissions
If your the fields you want to exclude are 1) created with CCK and 2) should be hidden from users of that role everywhere on the site (not just in this particular view) then you can just set the permissions on the fields so that users are particular roles can't view them. If the current user doesn't have permissions to view a field that is part of a View, the field won't be shown to the user.

How to add the UserId parameter to the query string of a XmlUrlDataSource in SharePoint?

I have an aspx that returns XML data using the query string parameter UserId. This UserId should be the SharePoint current User.
I create the datasource and dragged to the page, but i don't know how to add the parameter to the datasource, so that it sends the current User Id. I tried to add the parameter in the datasource parameters grid but when the aspx gets called it always uses the default value and not the current user id
You should be able to do this by adding a parameter through the context menu of the control (i.e. the DataFormWebPart) in design menu.

Resources