I had a situation where it would be nice if I could permissions at the view level. Over a year ago, I had a similar problem, but that time I told the client there was no way to set permissions at the view.
Here is a solution to set permissions at a view level. I will take a pages library in my example. In this example, if the current user does not belong to site owners group, they would be redirected to home page.
Assumptions
- Pages Library provisioned
Solution
- Create a new .JS file and add it to anywhere on the site (Hint: SiteAssets)
- Add code like this below
- Goto AllItems.aspx page/view and click edit.
- Add a CE to the page.
- Link the CE to this .JS file. (That is all required)
<script src="http://code.jquery.com/jquery-1.11.0.js" type="text/javascript"></script>
<script src="/SiteAssets/jquery.SPServices-0.7.1a.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
//Do this for All Documents Views. The regular user does not need to view "All Documents" view.
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
if ($(xData.responseXML).find("Group[Name='Site Owners']").length != 1) {
location.href = location.href.replace('/Forms/AllItems.aspx', '/Default.aspx');
}
}
});
});
No comments:
Post a Comment