设为首页 收藏本站
查看: 1361|回复: 0

[经验分享] SharePoint 2010 技巧系列: 控制Ribbon菜单权限(SiteActions的例子)

[复制链接]

尚未签到

发表于 2015-9-25 11:43:11 | 显示全部楼层 |阅读模式
  上一篇写了一个关于快速开发Ribbon菜单的例子,这次我们共同探讨一下Ribbon菜单权限的控制. 如果你已经阅读了 “”, 我相信你已经能很快的开发一个Ribbon菜单,这时我们就需要去关注Ribbon菜单其它更深的东西,比如给Ribbon添加链接,Ribbon脚本,Ribbon权限控制等等.
  当我们创建一个默认的SharePoint站点的时候,我们通过Site Actions –> Site Permission (站点权限) –> PermissionLevel, 我们可以看到SharePoint默认的几个权限级别: Full Control, Design, Contribute, Read,  Limited Access, View Only, 当然你能看到这些权限的级别还跟创建站点时选择的模板有关, 这里的重点不是权限级别, 而且更底层的权限分类. 直接点击上面任何一个权限级别, 以Contribute 为例, 你能看到SharePoint 基本的权限类型.


DSC0000.png   我们可以看下SharePoint SDK SPBasePermission与上图对应的权限类型.

#region Assembly Microsoft.SharePoint.dll, v2.0.50727
// C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll
#endregion
using System;
namespace Microsoft.SharePoint
{
// Summary:
//     Specifies the built-in permissions available in Windows SharePoint Services.
[Flags]
public enum SPBasePermissions
{
// Summary:
//     Has no permissions on the Web site. Not available through the user interface.
EmptyMask = 0,
//
// Summary:
//     View items in lists, documents in document libraries, and view Web discussion
//     comments.
ViewListItems = 1,
//
// Summary:
//     Add items to lists, add documents to document libraries, and add Web discussion
//     comments.
AddListItems = 2,
//
// Summary:
//     Edit items in lists, edit documents in document libraries, edit Web discussion
//     comments in documents, and customize Web Part Pages in document libraries.
EditListItems = 4,
//
// Summary:
//     Delete items from a list, documents from a document library, and Web discussion
//     comments in documents.
DeleteListItems = 8,
//
// Summary:
//     Approve a minor version of a list item or document.
ApproveItems = 16,
//
// Summary:
//     View the source of documents with server-side file handlers.
OpenItems = 32,
//
// Summary:
//     View past versions of a list item or document.
ViewVersions = 64,
//
// Summary:
//     Delete past versions of a list item or document.
DeleteVersions = 128,
//
// Summary:
//     Discard or check in a document which is checked out to another user.
CancelCheckout = 256,
//
// Summary:
//     Create, change, and delete personal views of lists.
ManagePersonalViews = 512,
//
// Summary:
//     Create and delete lists, add or remove columns in a list, and add or remove
//     public views of a list.
ManageLists = 2048,
//
// Summary:
//     View forms, views, and application pages, and enumerate lists.
ViewFormPages = 4096,
//
// Summary:
//     Allow users to open a Web site, list, or folder to access items inside that
//     container.
Open = 65536,
//
// Summary:
//     View pages in a Web site.
ViewPages = 131072,
//
// Summary:
//     Add, change, or delete HTML pages or Web Part Pages, and edit the Web site
//     using a Windows SharePoint Services–compatible editor.
AddAndCustomizePages = 262144,
//
// Summary:
//     Apply a theme or borders to the entire Web site.
ApplyThemeAndBorder = 524288,
//
// Summary:
//     Apply a style sheet (.css file) to the Web site.
ApplyStyleSheets = 1048576,
//
// Summary:
//     View reports on Web site usage.
ViewUsageData = 2097152,
//
// Summary:
//     Create a Web site using Self-Service Site Creation.
CreateSSCSite = 4194304,
//
// Summary:
//     Create subsites such as team sites, Meeting Workspace sites, and Document
//     Workspace sites.
ManageSubwebs = 8388608,
//
// Summary:
//     Create a group of users that can be used anywhere within the site collection.
CreateGroups = 16777216,
//
// Summary:
//     Create and change permission levels on the Web site and assign permissions
//     to users and groups.
ManagePermissions = 33554432,
//
// Summary:
//     Enumerate files and folders in a Web site using Microsoft Office SharePoint
//     Designer 2007 and WebDAV interfaces.
BrowseDirectories = 67108864,
//
// Summary:
//     View information about users of the Web site.
BrowseUserInfo = 134217728,
//
// Summary:
//     Add or remove personal Web Parts on a Web Part Page.
AddDelPrivateWebParts = 268435456,
//
// Summary:
//     Update Web Parts to display personalized information.
UpdatePersonalWebParts = 536870912,
//
// Summary:
//     Grant the ability to perform all administration tasks for the Web site as
//     well as manage content. Activate, deactivate, or edit properties of Web site
//     scoped Features through the object model or through the user interface (UI).
//     When granted on the root Web site of a site collection, activate, deactivate,
//     or edit properties of site collection scoped Features through the object
//     model. To browse to the Site Collection Features page and activate or deactivate
//     site collection scoped Features through the UI, you must be a site collection
//     administrator.
ManageWeb = 1073741824,
//
// Summary:
//     Use features that launch client applications; otherwise, users must work
//     on documents locally and upload changes.
UseClientIntegration = 68719476736,
//
// Summary:
//     Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces
//     to access the Web site.
UseRemoteAPIs = 137438953472,
//
// Summary:
//     Manage alerts for all users of the Web site.
ManageAlerts = 274877906944,
//
// Summary:
//     Create e-mail alerts.
CreateAlerts = 549755813888,
//
// Summary:
//     Allows a user to change his or her user information, such as adding a picture.
EditMyUserInfo = 1099511627776,
//
// Summary:
//     Enumerate permissions on the Web site, list, folder, document, or list item.
EnumeratePermissions = 4611686018427387904,
//
// Summary:
//     Has all permissions on the Web site. Not available through the user interface.
FullMask = 9223372036854775807,
}
}

  了解以上内容后,我们就能快速开发出带有权限控制的菜单了.
  1. 创建一个空的SharePoint 2010 项目,项目名:SiteActions Menu
  2. 右键点击Feature –> add Features, 添加一个新Feature,更改名称和描述.



DSC0001.png
  3. 右键点击项,添加一个Module, 打开Elements.xml 添加以下代码:


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="viewSiteManager"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Owner Menu" Description="control menu with user permission"
ImageUrl="colleagues_16.png"
Rights="ManagePermissions">
<UrlAction Url="~site/_layouts/sitemanager.aspx"/>
</CustomAction>
</Elements>

4. 代码中的红色部分是比较重要的属性,GroupId 和Location请参阅SDK,这里重点关注Rights, Rights属性的值,就是我们上面的SPbasePermission
的枚举值,可以用逗号隔开,比如 Rights= “ViewListItems,ManagePermissions”.

5, 部署运行查看效果.

DSC0002.png









6. 实例下载

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118644-1-1.html 上篇帖子: Developing SharePoint 2010 Search Solutions (Fast and SharePoint) 下篇帖子: SharePoint Portal Server与SharePoint Services之间的关系
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表