Example #1
0
        /// <summary>
        /// Add most of the WHERE part to a search sql
        /// </summary>
        /// <param name="portalId">
        /// portalID
        /// </param>
        /// <param name="userId">
        /// userID
        /// </param>
        /// <param name="select">
        /// SQL string to add sql to
        /// </param>
        /// <param name="fieldName">
        /// Field to do IS NOT NULL test on
        /// </param>
        public static void AddSharedSQL(int portalId, int userId, ref StringBuilder select, string fieldName)
        {
            var context = HttpContext.Current;
            var asRoles = PortalSecurity.GetRoles();

            /*
             * if (userID>-1)
             * select.Append(", rb_Roles, rb_UserRoles");
             * select.Append(" WHERE itm." + fieldName + " IS NOT NULL");
             * select.Append(" AND itm.ModuleID = mod.ModuleID");
             * select.Append(" AND mod.ModuleDefID = modDef.ModuleDefID");
             * select.Append(" AND modDef.PortalID = " + portalID.ToString());
             * select.Append(" AND tab.PortalID = " + portalID.ToString());
             * select.Append(" AND tab.TabID = mod.TabID");
             */

            if (userId > -1)
            {
                // select.Append(" AND rb_UserRoles.UserID = " + userID.ToString());
                // select.Append(" AND rb_UserRoles.RoleID = rb_Roles.RoleID");
                // select.Append(" AND rb_Roles.PortalID = " + portalID.ToString());
                select.Append(" AND ((mod.AuthorizedViewRoles LIKE '%All Users%') ");

                // - no tenia en cuenta el rol "Authenticated users"
                select.Append(
                    context.Request.IsAuthenticated
                        ? " OR (mod.AuthorizedViewRoles LIKE '%Authenticated Users%')"
                        : " OR (mod.AuthorizedViewRoles LIKE '%Unauthenticated Users%')");

                foreach (var sRole in asRoles)
                {
                    select.AppendFormat(" OR (mod.AuthorizedViewRoles LIKE '%{0}%')", sRole.Name);
                }

                select.Append(")");
                select.Append(" AND ((tab.AuthorizedRoles LIKE '%All Users%')");
                if (context.Request.IsAuthenticated)
                {
                    // - no tenia en cuenta el rol "Authenticated users"
                    select.Append(" OR (tab.AuthorizedRoles LIKE '%Authenticated Users%')");
                }

                foreach (var sRole in asRoles)
                {
                    select.AppendFormat(" OR (tab.AuthorizedRoles LIKE '%{0}%')", sRole.Name);
                }

                select.Append(")");
            }
            else
            {
                select.Append(" AND (mod.AuthorizedViewRoles LIKE '%All Users%')");
                select.Append(" AND (tab.AuthorizedRoles LIKE '%All Users%')");
            }
        }