Beispiel #1
0
        internal bool AddObjectToGroup(OCL.User AccessingUser, object Obj, OCL.Group CurrentGroup, out string ErrorMessage)
        {
            ErrorMessage = "";
            OCL.User DefaultUser = (OCL.User)GetUnassignedObject(OCL.OysterUnassignedObjects.User);
            OCL.OysterObjectType OBT = OysterObjectType.None;
            int ObjectTypeId = 0;
            int ObjectId = 0;
            string sType = "Unknown Type";

            /// A User Object is handled differently because each user gets his own copy
            /// the Default Permissions.
            if(Obj is OCL.User)
            {
                if(!CurrentGroup.CanAddUsers(AccessingUser))
                    return false;
                return AddUser(AccessingUser,(OCL.User)Obj,CurrentGroup,out ErrorMessage,false);
            }
            else if(Obj is OCL.RecordingSession)
            {
                if(!CurrentGroup.CanAddRecordingSessions(AccessingUser))
                    return false;
                return AddRecordingSession(AccessingUser,(OCL.RecordingSession)Obj,CurrentGroup,out ErrorMessage,false);
            }
            else if(Obj is OCL.Scene)
            {
                if(!CurrentGroup.CanAddScenes(AccessingUser))
                    return false;
                return AddScene(AccessingUser,(OCL.Scene)Obj,CurrentGroup,out ErrorMessage,false);
            }
            else
            {
                if(!GetObjectInfo(Obj,out OBT,out ObjectId))
                {
                    ErrorMessage = "Unknown Obj type or is unsupported by this function.";
                    return false;
                }
            }
            ObjectTypeId = Convert.ToInt32(OBT);

            /// Check to make sure object is not already member of Group
            String sSQL = "SELECT * FROM tblGroupTokens WHERE UserId = " + DefaultUser.mvarID +
                " AND GroupId = " + CurrentGroup.mvarID + " AND ObjectTypeId = " + ObjectTypeId +
                " AND ObjectId = " + ObjectId;
            DataSet DS = RF.GetDataSet(sSQL);
            if(DS.Tables[0].Rows.Count > 0)
            {
                ErrorMessage = sType + " already exist in Group";
                return false;
            }

            /// Create a Token for this Object for Default User within this Group
            OCL.Permission DP = GetDefaultObjectPermission(CurrentGroup,DefaultUser,OBT); //This gets the Users Default
            if(!InsertPermission(CurrentGroup,DefaultUser,OBT,ObjectId,DP.IsVisible,
                DP.CanAdd,DP.CanEdit,DP.CanDelete,DP.IsUsable,
                DP.CanEditPermission,DP.CanSeePermission,
                    DP.CanAddObjectA,DP.CanEditObjectA,DP.CanDeleteObjectA,
                    DP.CanAddObjectB,DP.CanEditObjectB,DP.CanDeleteObjectB,
                AccessingUser.mvarID,false))
            {
                ErrorMessage = sType + " failed to be added to Group for unknown reason";
                return false;
            }

            /// Create a Token for this Object for each Existing User

            /// Each Existing user's access token will reflect their own personal
            /// default permissions for this object type

            sSQL = "SELECT DISTINCT UserId FROM tblGroupTokens WHERE GroupId = " + CurrentGroup.mvarID +
                " AND UserId <> " + DefaultUser.mvarID;

            DataSet DSUsers = RF.GetDataSet(sSQL);
            foreach(DataRow r in DSUsers.Tables[0].Rows)
            {
                //Get Default Permissions for this object
                int CurrentUserId = Convert.ToInt32(r["UserId"]);
                OCL.User LocalCurrentUser = GetUser(CurrentUserId);
                int CurrenObjectTypeId = Convert.ToInt32(OCL.OysterObjectType.User);
                int DefaultObjectId = DefaultUser.mvarID;
                sSQL = "SELECT IsDefault,IsVisible, CanAdd, CanEdit, CanDelete, IsUsable,CanEditPermissions,CanSeePermissions, " +
                    "CanAddObjectA,CanEditObjectA,CanDeleteObjectA, " +
                    "CanAddObjectB, CanEditObjectB,CanDeleteObjectB FROM tblGroupTokens" +
                    " WHERE GroupId = " + CurrentGroup.mvarID + " AND UserId = " + CurrentUserId +
                    " AND ObjectTypeId = " + CurrenObjectTypeId + " AND ObjectId = " + DefaultObjectId;

                DataRow DRPerm = RF.GetDataSet(sSQL).Tables[0].Rows[0];
                bool IsDefault = Convert.ToBoolean(DRPerm["IsDefault"]);
                bool IsVisible = Convert.ToBoolean(DRPerm["IsVisible"]);
                bool CanAdd = Convert.ToBoolean(DRPerm["CanAdd"]);
                bool CanEdit = Convert.ToBoolean(DRPerm["CanEdit"]);
                bool CanDelete = Convert.ToBoolean(DRPerm["CanDelete"]);
                bool IsUsable = Convert.ToBoolean(DRPerm["IsUsable"]);
                bool CanEditPermission = Convert.ToBoolean(DRPerm["CanEditPermissions"]);
                bool CanSeePermission = Convert.ToBoolean(DRPerm["CanSeePermissions"]);
                bool CanAddObjectA = Convert.ToBoolean(DRPerm["CanAddObjectA"]);
                bool CanEditObjectA = Convert.ToBoolean(DRPerm["CanEditObjectA"]);
                bool CanDeleteObjectA = Convert.ToBoolean(DRPerm["CanDeleteObjectA"]);
                bool CanAddObjectB = Convert.ToBoolean(DRPerm["CanAddObjectB"]);
                bool CanEditObjectB = Convert.ToBoolean(DRPerm["CanEditObjectB"]);
                bool CanDeleteObjectB = Convert.ToBoolean(DRPerm["CanDeleteObjectB"]);
                try
                {
                    if(!InsertPermission(CurrentGroup,LocalCurrentUser,OBT,ObjectId,IsVisible,
                        CanAdd,CanEdit,CanDelete,IsUsable,
                        CanEditPermission,CanSeePermission,
                        CanAddObjectA,CanEditObjectA,CanDeleteObjectA,
                        CanAddObjectB, CanEditObjectB,CanDeleteObjectB,AccessingUser.mvarID,false))
                    {
                        ErrorMessage = sType + " failed to be added to Group for unknown reason";
                        return false;
                    }
                }
                catch(Exception Err)
                {
                    ErrorMessage = Err.Message;
                    return false;
                }
            }

            ErrorMessage = "";
            return true;
        }