Beispiel #1
0
        internal static void UpdateManager(int documentId, int managerId, bool checkAccess)
        {
            if (checkAccess)
            {
                VerifyCanUpdate(documentId);
            }

            int oldManagerId = DBDocument.GetManager(documentId);

            if (oldManagerId != managerId)
            {
                using (DbTransaction tran = DbTransaction.Begin())
                {
                    DbDocument2.UpdateManager(documentId, managerId);

                    // TODO: implement Document_Updated_Manager
                    // SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_Manager, documentId);

                    // OZ: User Role Addon
                    if (managerId != oldManagerId)
                    {
                        UserRoleHelper.DeleteDocumentManagerRole(documentId, oldManagerId);
                        UserRoleHelper.AddDocumentManagerRole(documentId, managerId);
                    }
                    // end OZ

                    tran.Commit();
                }
            }
        }
Beispiel #2
0
        private static void UpdateListResources(int objectId, DataTable items, bool checkAccess)
        {
            if (checkAccess)
            {
                VerifyCanUpdate(objectId);
            }

            int managerId = -1;

            using (IDataReader reader = DBDocument.GetDocument(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId))
            {
                reader.Read();
                managerId = (int)reader["ManagerId"];
            }

            ArrayList oldItems = new ArrayList();

            using (IDataReader reader = DBDocument.GetListResources(objectId, Security.CurrentUser.TimeZoneId))
            {
                Common.LoadPrincipals(reader, oldItems);
            }

            ArrayList add = new ArrayList();
            ArrayList del = new ArrayList();

            foreach (DataRow row in items.Rows)
            {
                int id = (int)row["PrincipalId"];
                if (oldItems.Contains(id))
                {
                    oldItems.Remove(id);
                }
                else
                {
                    add.Add(id);
                }
            }

            del.AddRange(oldItems);

            using (DbTransaction tran = DbTransaction.Begin())
            {
                foreach (int id in del)
                {
                    DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id);
                    DBDocument.DeleteResource(objectId, id);

                    // OZ: User Role Addon
                    UserRoleHelper.DeleteDocumentResourceRole(objectId, id);
                    if (id != managerId)
                    {
                        UserRoleHelper.DeleteDocumentManagerRole(objectId, id);
                    }
                    //
                    SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_AssignmentDeleted, objectId, id);
                }

                foreach (DataRow row in items.Rows)
                {
                    int  id = (int)row["PrincipalId"];
                    bool mustBeConfirmed = (bool)row["MustBeConfirmed"];
                    bool canManage       = (bool)row["CanManage"];
                    bool updated         = true;

                    if (add.Contains(id))
                    {
                        DbDocument2.ResourceAdd(objectId, id, mustBeConfirmed, canManage);
                        if (User.IsExternal(id))
                        {
                            DBCommon.AddGate((int)OBJECT_TYPE, objectId, id);
                        }
                    }
                    else
                    {
                        updated = (0 < DbDocument2.ResourceUpdate(objectId, id, mustBeConfirmed, canManage));
                    }

                    // OZ: User Role Addon
                    if (canManage)
                    {
                        if (id != managerId)
                        {
                            UserRoleHelper.AddDocumentManagerRole(objectId, id);
                        }
                    }
                    else
                    {
                        UserRoleHelper.AddDocumentResourceRole(objectId, id);
                    }
                    // end

                    if (updated)
                    {
                        if (mustBeConfirmed)
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_RequestAdded, objectId, id);
                        }
                        else
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_AssignmentAdded, objectId, id);
                        }
                    }
                }

                tran.Commit();
            }
        }