SharePoint/WSS:修改“创建者” 场地?

发布于 2024-07-25 03:02:56 字数 333 浏览 4 评论 0原文

全部 -

我正在使用 WSS 3.0。 目前,HR 会将员工的公司内部简历上传到我们网站上的文档库,但出于隐私原因,我们必须限制对该文档库的访问,这迫使用户每次想要更新简历时都必须通过 HR。

我的想法是创建一个启用附件的列表,允许用户仅查看/编辑自己的项目,然后授予 HR 管理所有条目的权限。 例外情况是 HR 需要创建初始列表项并附加简历,这意味着列表项将“由 {hr} 创建”,并且附加简历的最终用户不可见/不可编辑。

关于如何允许人力资源部修改上传时的“创建者”字段以便最终用户可以看到并可以编辑他们的简历,或者以不同的方式进行此操作,有什么想法吗?

谢谢!

All -

I am using WSS 3.0. Currently, HR will upload an employee's internal company resume to a document library on our site, but for privacy reasons, we must then restrict access to that document library, which forces users to then go through HR each time they want to update their resume.

My thought is to create a list with attachments enabled that allows users to only view/edit their own items, and then give HR permission to manage all entries. This works with the exception that HR will need to create the initial list item and attach the resume, which means the list item will be "created by {hr}" and not visible/editable by the end user whose resume is attached.

Any ideas on how I can either allow HR to modify the "created by" field on upload so end users will see and can edit their resume, or go about this in a different way?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泛泛之交 2024-08-01 03:02:56

创建一个文档库来保存简历。 然后授予人力资源部门(SharePoint 用户组)对库的“读/写所有”权限,并授予其他人“读/写您自己的”权限。根据以下内容创建一个名为“简历”的内容类型:然后添加一个包含简历所关注的员工(SPUser 字段)的字段(以及任何其他必需字段,即姓名、地址等)。 (使字段成为必填项)。

然后,编写一个绑定到您刚刚创建的内容类型的 itemeventreceiver 并覆盖 ItemUpdated 事件。

代码如下所示:

public override void ItemUpdated(SPItemEventProperties properties)
{
  SPSecurity.RunWithElevatedPrivileges(delegate
  {
    using (SPWeb web = properties.OpenWeb())
    {
       web.AllowUnsafeUpdates = true; 
       var item = web.Lists[properties.ListId].GetItemById(properties.ListItemId);
       if (item != null)
       {
         if (item.Fields.ContainsField("Employee"))
         {
           item["Author"] = item["Employee"]; 
           // Author is the internal name of the Created by field, 
           // always use Internal Names!
           DisableEventFiring();
           item.SystemUpdate();
           EnableEventFiring();
         }
       }
     }
   });
}

您可以使用 FeatureReceiver 将 ItemEventReceiver 绑定到内容类型,如下所示:

SPContentType docCt = web.ContentTypes[new SPContentTypeId("CONTENTYPE ID GOES HERE")];
docCt.EventReceivers.Add(SPEventReceiverType.ItemUpdated, "ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TOKEN", "FULLY QUALIFIED CLASSNAME");
docCt.Update();

Create a document library to hold the resume's. Then give the HR department (SharePoint User group) "read / write all" permissions on the library, the give everyone else read / write your own" rights. Create a Content Type called "Resume" based on the out-of-the-box Document content type. Then add a field that contains the Employee (SPUser field) whom the resume concerns to the content type (and any other fields required, i.e. name, address etc.). Have HR fill this in correctly when creating the listitem (make the fields required).

Then, write a itemeventreceiver bound to the content type you just created and override the ItemUpdated event.

The code would be something like the following:

public override void ItemUpdated(SPItemEventProperties properties)
{
  SPSecurity.RunWithElevatedPrivileges(delegate
  {
    using (SPWeb web = properties.OpenWeb())
    {
       web.AllowUnsafeUpdates = true; 
       var item = web.Lists[properties.ListId].GetItemById(properties.ListItemId);
       if (item != null)
       {
         if (item.Fields.ContainsField("Employee"))
         {
           item["Author"] = item["Employee"]; 
           // Author is the internal name of the Created by field, 
           // always use Internal Names!
           DisableEventFiring();
           item.SystemUpdate();
           EnableEventFiring();
         }
       }
     }
   });
}

you can bind the ItemEventReceiver using a FeatureReceiver to the content type like so:

SPContentType docCt = web.ContentTypes[new SPContentTypeId("CONTENTYPE ID GOES HERE")];
docCt.EventReceivers.Add(SPEventReceiverType.ItemUpdated, "ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TOKEN", "FULLY QUALIFIED CLASSNAME");
docCt.Update();
卸妝后依然美 2024-08-01 03:02:56

为什么不直接使用文档库来保存简历呢? (而不是带有附件的列表。)您可以向 HR 授予对其中所有文档的完全读/写权限,并且简历的所有者将仅拥有对自己的简历进行贡献的权限。

Why not just use a document library for the resumes? (instead of a list w/ attachments.) You can give HR full read/write to all documents within, and the owner of the resume will have contribute permissions to only their own resume.

请爱~陌生人 2024-08-01 03:02:56

我找到了一种使用 SharePoint Designer 更改“创建者”字段来创建工作流的方法。

  1. 使用易于识别的名称在列表中创建一个虚拟字段,例如
    XYZZY。 使其成为“个人或团体”字段。
  2. 在 SharePoint Designer 中,为您的列表创建工作流。 允许手动启动并在创建新项目时自动启动。
  3. 行动-> 在当前项目中设置字段 -> 将 XYZZY 设置为列表中包含要放入创建者的用户帐户的字段。
  4. 单击
  5. “立即完成”,使用记事本打开工作流程 .xoml 文件。 将“XYZZY”替换为“作者”。 保存 .xoml 文件。
  6. 在 Designer 中打开工作流程。 单击“完成”,以便使用新代码重新处理。
  7. 从列表中删除虚拟字段。
  8. 对列表中的每个现有项目运行工作流程。 新项目将自动进行自我更正。

I found a way to change the Created By field using SharePoint Designer to create a workflow.

  1. Create a dummy field in your list with an easy-to-spot name, e.g.
    XYZZY. Make it a "person or group" field.
  2. In SharePoint Designer, create a Workflow for your list. Allow manual start and start automatically when new item is created.
  3. Actions -> Set Field in Current Item -> Set XYZZY to the field in your list that contains the user account you want to put into Created By.
  4. Click Finish
  5. Now, open your workflow .xoml file with Notepad. Replace "XYZZY" with "Author". Save the .xoml file.
  6. Open the workflow in Designer. Click Finish so that it reprocesses with the new code.
  7. Delete the dummy field from the list.
  8. Run the workflow on each existing item in your list. New items will self-correct automatically.
奈何桥上唱咆哮 2024-08-01 03:02:56

使用自定义上传屏幕,您可以在上传之前更改当前用户的上下文。 它需要使用类似以下内容查找用户令牌(这些是工作代码片段,其中包含错误处理和删除的其他内容)。 请注意,EnsureUser 将要求当前用户基本上是管理员/所有者。

using (SPSite site = GetImpersonatedSite(runAsUser))
{
    using (SPWeb web = site.OpenWeb())
    {
        // Do stuff here
    }
}

private SPSite GetImpersonatedSite(string username)
{
    user = SPContext.Current.Web.EnsureUser(username);
    SPSite site = new SPSite(SPContext.Current.Web.Url, user.UserToken);
    return site;
}

With a custom upload screen you could change the context of the current user before doing the upload. It requires looking up the user token using something like the following (these are snippets of working code with error handling and other stuff removed). Note that EnsureUser will require that the current user basically be an admin/owner.

using (SPSite site = GetImpersonatedSite(runAsUser))
{
    using (SPWeb web = site.OpenWeb())
    {
        // Do stuff here
    }
}

private SPSite GetImpersonatedSite(string username)
{
    user = SPContext.Current.Web.EnsureUser(username);
    SPSite site = new SPSite(SPContext.Current.Web.Url, user.UserToken);
    return site;
}
沉睡月亮 2024-08-01 03:02:56

我遇到过类似的情况(迁移到共享点),我必须将具有管理员用户的文件添加到文档库,然后“更改”用户。 我是这样做的,可能会对你有所帮助:

using (var root = site.RootWeb)
 {
   var users = root.SiteUsers;
   var user = users["domain\username"];
   file.Item[SPBuiltInFieldId.Created_x0020_By] = user.ID;
   file.Item[SPBuiltInFieldId.Modified_x0020_By] = user.ID;
   file.Item.UpdateOverwriteVersion();

I had a similar situation (migration into sharepoint) where I had to add a file with the admin user to a doc library and then "change" the users. I did it like this, might help you somewhat:

using (var root = site.RootWeb)
 {
   var users = root.SiteUsers;
   var user = users["domain\username"];
   file.Item[SPBuiltInFieldId.Created_x0020_By] = user.ID;
   file.Item[SPBuiltInFieldId.Modified_x0020_By] = user.ID;
   file.Item.UpdateOverwriteVersion();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文