Bug reports Found a bug? Post it here please.
Version 5.x > Bug reports > Deleted user and CMS_Document.DocumentCreatedByUserID problem. How to prevent user deletion? View modes: 
User avatar
Member
Member
ricardo.fiel - 1/10/2011 5:49:36 AM
   
Deleted user and CMS_Document.DocumentCreatedByUserID problem. How to prevent user deletion?
Hi all,

We're having a problem with a live site. A user was deleted and all of it's associated documents now have the DocumentCreatedbyuserID column set to null.

Is there a way to prent this? The ideal solution would be to not let any user with created documents being deleted.

Thanks,
Ricardo

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/10/2011 8:46:16 AM
   
RE:Deleted user and CMS_Document.DocumentCreatedByUserID problem. How to prevent user deletion?
Hi,

You can check if some document created by user exists or not. You could add this functionality into file ~/CMSSiteManager/Administration/Users/User_List.aspx.cs and modify method protected void gridElem_OnAction(string actionName, object actionArgument). In else if (actionName == "delete") part you could add following code:
// It is not possible to delete user whose documents exists in CMS.Document table
DataSet ds = null;
// Tree provider
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);
tree.MergeResults = true;
ds = CMS.WorkflowEngine.DocumentHelper.GetDocuments(TreeProvider.ALL_SITES, TreeProvider.ALL_DOCUMENTS, TreeProvider.ALL_CULTURES, false, "", "DocumentCreatedByUserID="+ delUser.UserID, "", TreeProvider.ALL_LEVELS, false, tree);

if (ds.Tables[0].Rows.Count > 0)
{
lblError.Visible = true;
lblError.Text = "ds is not null";
return;
}


With above modification you cannot delete user in Site Manager - Administration - Users in case some document created by appropriate user exists.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
ricardo.fiel - 1/10/2011 9:02:40 AM
   
RE:Deleted user and CMS_Document.DocumentCreatedByUserID problem. How to prevent user deletion?
Thanks. I'll make this changes in project.

Regards,
Ricardo