Exemplo n.º 1
0
        //----------------------------------------------------------------------------------------------------
        public PermissionValues CheckPermissions(int connectionId, string schema, int tableId)
        {
            if (this.IsAdmin)
            {
                return new PermissionValues()
                       {
                           View = true, Edit = true, Insert = true, Delete = true
                       }
            }
            ;

            var rtn = new PermissionValues();

            if (this.PermissionValuesDict == null)
            {
                return(rtn);
            }

            string key1 = "C_" + connectionId;
            string key2 = "S_" + connectionId + "_" + schema.ToLower();
            string key3 = "T_" + connectionId + "_" + schema.ToLower() + "_" + tableId;

            if (this.PermissionValuesDict.ContainsKey(key1))
            {
                UpdateTrues_InPermissionValues(this.PermissionValuesDict[key1], rtn);
            }
            if (this.PermissionValuesDict.ContainsKey(key2))
            {
                UpdateTrues_InPermissionValues(this.PermissionValuesDict[key2], rtn);
            }
            if (this.PermissionValuesDict.ContainsKey(key3))
            {
                UpdateTrues_InPermissionValues(this.PermissionValuesDict[key3], rtn);
            }

            if (!rtn.View)
            {
                if (rtn.Edit || rtn.Insert || rtn.Delete)
                {
                    rtn.View = true;
                }
            }

            return(rtn);
        }
Exemplo n.º 2
0
 //----------------------------------------------------------------------------------------------------
 private void UpdateTrues_InPermissionValues(PermissionValues source, PermissionValues target)
 {
     if (source.View)
     {
         target.View = true;
     }
     if (source.Edit)
     {
         target.Edit = true;
     }
     if (source.Insert)
     {
         target.Insert = true;
     }
     if (source.Delete)
     {
         target.Delete = true;
     }
 }
Exemplo n.º 3
0
        //----------------------------------------------------------------------------------------------------
        public static AllPermissionsInfo LoadAllPermissions(int userId, bool isAdmin)
        {
            AjaxService.ASPdatabaseService.GetSetVal();
            var rtn = new AllPermissionsInfo()
            {
                UserId = userId, IsAdmin = isAdmin
            };

            if (isAdmin)
            {
                return(rtn);
            }
            rtn.PermissionValuesDict = new Dictionary <string, PermissionValues>();

            string sql = String.Format(@"
                select 
                    T2.[GroupId], T2.[GroupName],
                    T3.[PermissionType], T3.[ConnectionId], T3.[Schema], T3.[TableId], T3.[View], T3.[Edit], T3.[Insert], T3.[Delete]
                from 
                    [{0}].[ASPdb_UsersToGroups] as T1
                inner join 
                    [{0}].[ASPdb_UserGroups] as T2 on T1.[GroupId] = T2.[GroupId]
                inner join
                    [{0}].[ASPdb_Permissions] as T3 on T1.[GroupId] = T3.[GroupId]
                where 
                    T1.[UserId] = @UserId and T2.[Active] = 1
                order by 
                    T3.[ConnectionId], T3.[Schema], T3.[TableId]
                ", Config.SystemProperties.AppSchema);

            using (DbConnectionCommand command = UniversalADO.OpenConnectionCommand(sql))
            {
                command.AddParameter("@UserId", userId);
                using (DbReaderWrapper reader = command.ExecuteReaderWrapper())
                {
                    while (reader.Read())
                    {
                        string permissionType   = reader.Get("PermissionType", "");
                        int    connectionId     = reader.Get("ConnectionId", -1);
                        string schema           = reader.Get("Schema", "");
                        int    tableId          = reader.Get("TableId", -1);
                        var    permissionValues = new PermissionValues()
                        {
                            View   = reader.Get("View", false),
                            Edit   = reader.Get("Edit", false),
                            Insert = reader.Get("Insert", false),
                            Delete = reader.Get("Delete", false)
                        };
                        string key = "";
                        switch (permissionType)
                        {
                        case "C": key = "C_" + connectionId; break;

                        case "S": key = "S_" + connectionId + "_" + schema.ToLower(); break;

                        case "T": key = "T_" + connectionId + "_" + schema.ToLower() + "_" + tableId; break;
                        }
                        if (!rtn.PermissionValuesDict.ContainsKey(key))
                        {
                            rtn.PermissionValuesDict.Add(key, permissionValues);
                        }
                    }
                }
            }
            return(rtn);
        }