Esempio n. 1
0
        /// <summary>
        /// Getting Group to Contenet Permission Information
        /// </summary>
        /// <param name="groupID">Group ID to get permission for.</param>
        /// <param name="associationType">Assign, UnAssign, NotAssigned</param>
        /// <returns>List of MGSecurityTag </returns>
        public List <MGSecurityTag> GetGroupContentDictionary(int groupID, GroupAdministration.AssociationTypes associationType)
        {
            List <MGSecurityTag> groupTags = null;
            string sql = null;

            Logger.Log("Start getting the group to content dictionary given a group id and assiciation type.");

            try
            {
                sql = GroupQB.GetSelectGroupContentPermissionSql(groupID, associationType);

                // TODO: make this checking and single list from single entry dictionary retrieval into a method
                List <string[]> data = dbInfo.GetDataList(sql);
                if (data == null)
                {
                    Logger.LogError(5, "Error getting group to content permissions for sql: " + sql);
                    return(null);
                }
                else if (data.Count == 0)
                {
                    Logger.Log("No record was found in the database for sql :" + sql);
                    return(new List <MGSecurityTag>());
                }

                Logger.Log("Start building the Security Dictionary.");
                bool isCheckForUniqVals = false;
                Dictionary <int, List <MGSecurityTag> > dict = BuildSecurityDictionary(data, isCheckForUniqVals);
                if (dict == null)
                {
                    Logger.LogError(5, "Error, got Null Security Dictionary. Quitting!");
                    return(null);
                }
                else if (dict.Count == 0)
                {
                    Logger.LogError(5, "Error, got Empty Security Dictionary. Quitting!");
                    return(null);
                }
                else if (dict.Count > 1)
                {
                    Logger.LogError(5, "TODO: write log");
                    return(null);
                }
                else if (!dict.ContainsKey(groupID))
                {
                    Logger.LogError(5, "Error, required group id is not found in the Security Dictionary. Quitting!");
                    return(null);
                }

                Logger.Log("Start Getting Security Tag.");
                groupTags = dict[groupID];
                if (groupTags == null)
                {
                    Logger.LogError(5, "Error, Null Security Tag found. Quitting!");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error Getting Group to Content Permission Information at " + ex);
                return(null);
            }
            return(groupTags);
        }
Esempio n. 2
0
        public List <MGSecurityTag> GetUnassignedAnyGroupContentDictionary()
        {
            // This gets permissions that are NOT assigned to ANY group:
            // TODO: generate this query in a method that can be called for all three types of group permission (content, display & functionality)

            List <MGSecurityTag> groupTags = null;
            string sql = "";

            try
            {
                sql = GroupQB.GetSelectGroupContentPermissionSql(MGGroup.NO_GROUP_GROUP_ID, GroupAdministration.AssociationTypes.NotAssigned);
                // TODO: make this checking and single list from single entry dictionary retrieval into a method

                List <string[]> data = dbInfo.GetDataList(sql);
                if (data == null)
                {
                    Logger.LogError(5, "Failed to get the conents from database which are not linked to any group using SQL = " + sql);
                    return(null);
                }
                else if (data.Count == 0)
                {
                    return(new List <MGSecurityTag>());
                }
                //return BuildSecurityDictionary(data)[MGGroup.NO_GROUP_GROUP_ID];

                Dictionary <int, List <MGSecurityTag> > dict = BuildSecurityDictionary(data);
                if (dict == null)
                {
                    Logger.LogError(5, "Error converting into Dictionary the contents permission which not linked to any group.");
                    return(null);
                }
                else if (dict.Count == 0)
                {
                    Logger.Log("Got zero unassigned to any group content items, returning an empty list of security tags ...");
                    return(new List <MGSecurityTag>());
                }
                else if (dict.Count > 1)
                {
                    Logger.LogError(5, "Invalid number of entries are found in the Dictionary for contents permission which not linked to any group.");
                    Logger.LogError(5, "Every content is set to belong to a dumy Group with ID = 1. Therefore there should be only one entry in the dictionary.");
                    return(null);
                }
                else if (!dict.ContainsKey(MGGroup.NO_GROUP_GROUP_ID))
                {
                    Logger.LogError(5, "Dictionary does not containd the contents entries for the dumy group.");
                    return(null);
                }

                groupTags = dict[MGGroup.NO_GROUP_GROUP_ID];
                if (groupTags == null)
                {
                    Logger.LogError(5, "Could not find the MGSecurityTag for " + MGGroup.NO_GROUP_GROUP_NAME);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(5, "Error Getting Content Permission Information for Contents which are not linked to any group at " + ex);
                return(null);
            }
            return(groupTags);
        }