Exemplo n.º 1
0
        public bool EnsurePermissionsInDatabase()
        {
            bool ret = true;

            if (!ensuredInDatabase)
            {
                ret = PortalApplicationPermission.EnsurePermissionsInDatabase(this);
                ensuredInDatabase = true;
            }
            return(ret);
        }
Exemplo n.º 2
0
 public void RemoveUserPermission(PortalApplicationPermission permissionToRemove)
 {
     foreach (PortalApplicationPermission p in Permissions)
     {
         if (p.ID == permissionToRemove.ID)
         {
             ApplicationPermissions.Remove(p);
             return;
         }
     } // foreach
 }
Exemplo n.º 3
0
        /// <summary>
        /// adds a permission to the user's Permissions list. Does NOT save this addition to the database.
        /// </summary>
        /// <param name="role"></param>
        public void AddUserPermission(PortalApplicationPermission permission)
        {
            foreach (PortalApplicationPermission p in Permissions)
            {
                if (p.ID == permission.ID)
                {
                    return;
                }
            }

            ApplicationPermissions.Add(permission);
        }
Exemplo n.º 4
0
            } // Update

            private bool arrayContains(PortalApplicationPermission needle, PortalApplicationPermission[] haystack)
            {
                foreach (PortalApplicationPermission p in haystack)
                {
                    if ((String.Compare(needle.ApplicationName, p.ApplicationName, true) == 0) &&
                        (String.Compare(needle.Action, p.Action, true) == 0))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemplo n.º 5
0
            private PortalApplicationPermission GetFromRow(DataRow dr)
            {
                PortalApplicationPermission item = new PortalApplicationPermission();

                item.ID = Convert.ToInt32(dr["PermissionsId"]);

                item.ApplicationName = (dr["ApplicationName"]).ToString();

                item.Action = (dr["Action"]).ToString();

                item.Description = (dr["Description"]).ToString();

                return(item);
            } // GetFromRow
Exemplo n.º 6
0
            } // Insert

            public bool Update(PortalApplicationPermission item)
            {
                string sql = "UPDATE permissions SET ";

                sql += "ApplicationName = " + "'" + dbEncode(item.ApplicationName) + "'" + ", ";
                sql += "Action = " + "'" + dbEncode(item.Action) + "'" + ", ";
                sql += "Description = " + "'" + dbEncode(item.Description) + "'" + ", ";

                sql += " WHERE PermissionsId = " + item.ID.ToString();
                sql += " ; ";

                int numAffected = this.RunUpdateQuery(sql);

                if (numAffected < 0)
                {
                    return(false);
                }
                return(true);
            } // Update
Exemplo n.º 7
0
            public bool Insert(PortalApplicationPermission item)
            {
                string sql = "INSERT INTO permissions ";

                sql += "(ApplicationName, Action, Description)";
                sql += " VALUES ( ";
                sql += "'" + dbEncode(item.ApplicationName) + "'" + ", ";
                sql += "'" + dbEncode(item.Action) + "'" + ", ";
                sql += "'" + dbEncode(item.Description) + "'" + ", ";

                sql += " ); ";

                int newId = this.RunInsertQuery(sql);

                if (newId > -1)
                {
                    item.ID = newId;
                    return(true);
                }
                return(false);
            } // Insert
Exemplo n.º 8
0
        }         // getAllWebPortalUsers

        /// <summary>
        /// returns an ArrayList of WebPortalUser objects. The passed in DataSet MUST have been created
        /// using getStandardUserSQL()
        /// </summary>
        /// <param name="ds">The DataSet returned from the query</param>
        /// <returns>an ArrayList of WebPortalUser objects</returns>
        private WebPortalUser[] getWebPortalUsersFromStandardDataSet(DataSet ds)
        {
            Dictionary <string, WebPortalUser> storage = new Dictionary <string, WebPortalUser>();

            if (hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string key = dr["AppUserId"].ToString();

                    // -- get the user
                    WebPortalUser user;
                    if (!storage.ContainsKey(key))
                    {
                        user              = new WebPortalUser(Convert.ToInt32(dr["AppUserId"]), dr["username"].ToString(), dr["password"].ToString());
                        user.FullName     = dr["FullName"].ToString();
                        user.EmailAddress = dr["EmailAddress"].ToString();
                        user.LastLogin    = getPossiblyNullValue(dr, "LastLoginDateTime", DateTime.MinValue);
                    }
                    else
                    {
                        user = storage[key];
                    }

                    // -- roles
                    if (dr["roleid"] != System.DBNull.Value)
                    {
                        WebPortalUserRole role = new WebPortalUserRole(Convert.ToInt32(dr["roleid"]), dr["RoleName"].ToString(), dr["RoleDesc"].ToString());
                        user.AddUserRole(role);
                    }

                    // x.`key` as exKey, x.`value` as exVal,


                    // -- Permissions
                    //      p.PermissionsId, p.ApplicationName, p.Action, p.Description
                    if (dr["PermissionsId"] != System.DBNull.Value)
                    {
                        PortalApplicationPermission p = new PortalApplicationPermission();
                        p.ID = Convert.ToInt32(dr["PermissionsId"]);
                        p.ApplicationName = dr["ApplicationName"].ToString().Trim();
                        p.Action          = dr["Action"].ToString().Trim();
                        p.Description     = dr["Description"].ToString();

                        user.AddUserPermission(p);
                    }


                    if (!storage.ContainsKey(key))
                    {
                        storage.Add(key, user);
                    }
                }         // foreach row
                          // ---- copy the storage NameValueCollection to the ArrayList
            }             // if there is data

            List <WebPortalUser> ret = new List <WebPortalUser>();

            foreach (string k in storage.Keys)
            {
                ret.Add(storage[k]);
            }

            return(ret.ToArray());
        }         // getWebPortalUsersFromStandardDataSet
Exemplo n.º 9
0
 public bool hasPermissionTo(PortalApplicationPermission permissionRequested)
 {
     return(hasPermissionTo(permissionRequested.Action, permissionRequested.ApplicationName));
 }
Exemplo n.º 10
0
 public static bool Delete(PortalApplicationPermission toDelete)
 {
     return((new permissionsDB()).Delete(toDelete.ID));
 } // Delete