Beispiel #1
0
        //public static WsFile DeleteDoc(string wsId, string wsLogFldrID, string docObjId, string comment = null)
        public static WsFile DeleteDoc(string wsId, string docObjId, string comment = null, bool toValidate = true)
        {
            IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(docObjId, isAdmin: true);

            if (!toValidate || WsValidation.ValidateDoc(imDoc, imDocumentOperation.imDeleteDocumentOp) == WsDocDelStatusType.Success)
            {
                //imDoc.Update();
                imDoc.LockContent(false);
                //imDoc.UnlockContent();
                IManProfileUpdateResult status = imDoc.UpdateWithResults();

                if (status.Succeeded)
                {
                    //Set Custom27 to true (Marked for deletion attribute)
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom27, true);

                    //Prefix document description with “DEL_”
                    if (!imDoc.Description.StartsWith(AmConst.CONST_DELETE_PREFIX))
                    {
                        imDoc.Description = AmConst.CONST_DELETE_PREFIX + imDoc.Description;
                    }

                    //Add a message to IWov history (see Autonomy’s documentation)
                    //imDoc.HistoryList.Add(imHistEvent.imHistoryDelete, 0, 0, AmConst.CONST_APP_NAME, AmConst.CONST_DELETE_COMMENT, "", "", "", null, null, null);
                    AddImHistoryInfo(imDoc, HistoryInfoType.DELETE);

                    //Store rollback information in the comments

                    //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897942)
                    //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897941)
                    //Grant right for NRTADMIN and Service Account to file.
                    //WsUtility.AddUserSecurity(imDoc, imAccessRight.imRightAll); -- Why?
                    WsUtility.AddGroupSecurity(imDoc, "NRTADMIN", imAccessRight.imRightAll);

                    imDoc.Security.DefaultVisibility = imSecurityType.imPrivate;

                    //Set owner and creator to DELETE USER
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER));
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER));

                    //Remove all security right and groups except for NRTADMIN group and Service Account -- Why?
                    foreach (IManUserACL userRight in imDoc.Security.UserACLs)
                    {
                        if (userRight.User.Name != "DELETEUSER")
                        {
                            //WsUtility.AddUserSecurity(imDoc, userRight.User.Name, imAccessRight.imRightNone);
                            userRight.Right = imAccessRight.imRightNone;
                        }
                    }

                    foreach (IManGroupACL groupRight in imDoc.Security.GroupACLs)
                    {
                        if (groupRight.Group.Name != "NRTADMIN")
                        {
                            //WsUtility.AddGroupSecurity(imDoc, groupRight.Group.Name, imAccessRight.imRightNone);
                            groupRight.Right = imAccessRight.imRightNone;
                        }
                    }

                    imDoc.Update();

                    imDoc.UnlockContent();

                    var wsGLog = new WsGenericLog();
                    wsGLog.ActionBy          = AmUtil.GetCurrentUser;
                    wsGLog.Id                = imDoc.Number;
                    wsGLog.Name              = imDoc.Description;
                    wsGLog.ActionInfo        = null;
                    wsGLog.AdditionalInfo    = null;
                    wsGLog.Comment           = comment;
                    wsGLog.OldValue          = null;
                    wsGLog.NewValue          = null;
                    wsGLog.WsLogActivityType = WsLogActivityType.DeleteFile;

                    WsUtility.CreateWsLog(wsId, wsGLog);
                }

                IManDocument imDocRet = WsUtility.GetObjectByID <IManDocument>(docObjId);

                return(Workspace.GetWsFile(imDocRet));
            }

            return(null);
        }