From: <ro...@us...> - 2006-08-10 21:11:50
|
Revision: 305 Author: rouquin Date: 2006-08-10 14:11:42 -0700 (Thu, 10 Aug 2006) ViewCVS: http://svn.sourceforge.net/tcdb/?rev=305&view=rev Log Message: ----------- Enabled roles on Administration page. Modified Paths: -------------- Website/App_Code/Products.cs Website/App_Code/Right.cs Website/App_Code/Users.cs Website/Includes/Administration.ascx Website/Includes/Administration.ascx.cs Website/Includes/UserRoles.ascx.cs Modified: Website/App_Code/Products.cs =================================================================== --- Website/App_Code/Products.cs 2006-08-10 20:22:04 UTC (rev 304) +++ Website/App_Code/Products.cs 2006-08-10 21:11:42 UTC (rev 305) @@ -53,6 +53,18 @@ return productList; } + public static List<User> TCDB_GetProductUsers(int productID, Nullable<int> roleID) + { + tcdbDataSetTableAdapters.db_roleProductUserTableAdapter rpuAdapter = new tcdbDataSetTableAdapters.db_roleProductUserTableAdapter(); + tcdbDataSet.db_roleProductUserDataTable rpuTable = rpuAdapter.GetData(roleID, productID, true); + List<User> userList = new List<User>(); + + foreach (tcdbDataSet.db_roleProductUserRow row in rpuTable) + userList.Add(UserDB.GetUserInfo(row.userID)); + + return userList; + } + public static void DeleteProduct(int productID) { Product product = GetProduct(productID); Modified: Website/App_Code/Right.cs =================================================================== --- Website/App_Code/Right.cs 2006-08-10 20:22:04 UTC (rev 304) +++ Website/App_Code/Right.cs 2006-08-10 21:11:42 UTC (rev 305) @@ -204,7 +204,8 @@ return roleList; } - public static Role TCDB_GetUserRoles(int productID, int userID, String roleName, Nullable<bool> active) + + public static Role TCDB_GetUserRole(int productID, int userID, String roleName, Nullable<bool> active) { tcdbDataSetTableAdapters.db_roleUserProductTableAdapter userRoleAdapter = new tcdbDataSetTableAdapters.db_roleUserProductTableAdapter(); tcdbDataSet.db_roleUserProductDataTable userRoleTable = userRoleAdapter.GetData(userID, productID, active); @@ -247,6 +248,24 @@ return true; } + + public static bool DeleteRole(int roleID) + { + Role role = GetRoleInfo(roleID); + + tcdbDataSetTableAdapters.db_roleTableAdapter roleAdapter = new tcdbDataSetTableAdapters.db_roleTableAdapter(); + try + { + roleAdapter.Update(role.ID, role.NAME, role.DESCRIPTION, false); + } + catch (Exception e) + { + m_logg.Error(e.Message); + return false; + } + + return true; + } } /// <summary> Modified: Website/App_Code/Users.cs =================================================================== --- Website/App_Code/Users.cs 2006-08-10 20:22:04 UTC (rev 304) +++ Website/App_Code/Users.cs 2006-08-10 21:11:42 UTC (rev 305) @@ -590,7 +590,7 @@ } public static bool HasRole(int userID, string role, int productID) { - return (RightDB.TCDB_GetUserRoles(productID, userID, role, true) != null); + return (RightDB.TCDB_GetUserRole(productID, userID, role, true) != null); } public bool HasRoles(int productID) { Modified: Website/Includes/Administration.ascx =================================================================== --- Website/Includes/Administration.ascx 2006-08-10 20:22:04 UTC (rev 304) +++ Website/Includes/Administration.ascx 2006-08-10 21:11:42 UTC (rev 305) @@ -113,7 +113,7 @@ <asp:Image ID="newRoleIcon" runat="server" SkinID="newRoleImage" AlternateText="New User" />New Role</asp:LinkButton></div> <div class="button"> - <asp:LinkButton ID="userRole" runat="server" OnInit="userRole_Init" CommandName="role" + <asp:LinkButton ID="userRole" runat="server" CommandName="user" OnCommand="Role_Command"> <asp:Image ID="userRoleIcon" runat="server" SkinID="userRoleImage" AlternateText="User Roles" />User Roles</asp:LinkButton></div> Modified: Website/Includes/Administration.ascx.cs =================================================================== --- Website/Includes/Administration.ascx.cs 2006-08-10 20:22:04 UTC (rev 304) +++ Website/Includes/Administration.ascx.cs 2006-08-10 21:11:42 UTC (rev 305) @@ -37,11 +37,6 @@ if (!m_user.HasRight(Constants.RIGHTS_ROLE_CREATE, Constants.PRODUCT_ANYID)) newRole.Visible = false; } - protected void userRole_Init(object sender, EventArgs e) - { - if (!m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_MY, Constants.PRODUCT_ANYID) && !m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_OTHER, Constants.PRODUCT_ANYID)) - userRole.Visible = false; - } protected void productList_Init(object sender, EventArgs e) { @@ -92,20 +87,16 @@ foreach (User user in users) { - foreach (Product product in products) - { - if (!(m_user.HasRight(Constants.RIGHTS_USER_VIEW_OTHER)) && - !(user.ID == m_user.ID && m_user.HasRight(Constants.RIGHTS_USER_VIEW_MY, product.ID)) && - !(m_user.HasRight(Constants.RIGHTS_USER_VIEW_OTHER, user, product.ID))) - continue; + if (!(m_user.HasRight(Constants.RIGHTS_USER_VIEW_OTHER)) && + !(user.ID == m_user.ID && m_user.HasRight(Constants.RIGHTS_USER_VIEW_MY, Constants.PRODUCT_ANYID)) && + !(m_user.HasRight(Constants.RIGHTS_USER_VIEW_OTHER, user, Constants.PRODUCT_ANYID))) + continue; - ListItem item = new ListItem(user.FULLNAME, user.ID.ToString()); - //if (!user.ACTIVE) - //item.Attributes.CssStyle.Add("text-decoration", "line-through"); + ListItem item = new ListItem(user.FULLNAME, user.ID.ToString()); + if (!user.ACTIVE) + item.Attributes.CssStyle.Add("text-decoration", "line-through"); - userList.Items.Add(item); - break; - } + userList.Items.Add(item); } if (!IsPostBack) userList_SelectedIndexChanged(sender, e); @@ -154,73 +145,61 @@ protected void roleList_Init(object sender, EventArgs e) { - //TODO: Turn this into stuff for roles! - - /* List<Product> products = ProductDB.GetProductList(active); - List<User> users = UserDB.TCDB_GetUserList(); + List<Role> roles = RightDB.TCDB_GetRoleList(active); - foreach (User user in users) + foreach (Role role in roles) { - foreach (Product product in products) - { - if (!(m_user.HasRight("view_other_settings")) && - !(user.ID == m_user.ID && m_user.HasRight("view_my_settings", product.ID)) && - !(m_user.HasRight("view_other_settings", user, product.ID))) - continue; + if (!(m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_OTHER, Constants.PRODUCT_ANYID)) && + !(m_user.HasRole(role.NAME) && m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_MY,Constants.PRODUCT_ANYID))) + continue; - ListItem item = new ListItem(user.FULLNAME, user.ID.ToString()); - //if (!user.ACTIVE) - //item.Attributes.CssStyle.Add("text-decoration", "line-through"); + ListItem item = new ListItem(role.NAME,role.ID.ToString()); + if (!role.ACTIVE) + item.Attributes.CssStyle.Add("text-decoration", "line-through"); - userList.Items.Add(item); - break; - } + roleList.Items.Add(item); } if (!IsPostBack) - userList_SelectedIndexChanged(sender, e); - */ + roleList_SelectedIndexChanged(sender, e); + } protected void roleList_SelectedIndexChanged(object sender, EventArgs e) { - //TODO: Turn this into stuff for roles! + Role role = RightDB.GetRoleInfo(Convert.ToInt32(roleList.SelectedValue)); + bool hasRole = m_user.HasRole(role.NAME); + userRole.Visible = true; + roleView.Visible = true; + roleEdit.Visible = true; + roleDelete.Visible = true; - /* - List<Product> products = ProductDB.GetProductList(active); - User user = UserDB.GetUserInfo(Convert.ToInt32(userList.SelectedValue)); + // userRole + if (!(m_user.HasRight(Constants.RIGHTS_ROLE_EDIT_USERS, Constants.PRODUCT_ANYID)) && + !(hasRole && m_user.HasRight(Constants.RIGHTS_ROLE_EDIT_MY, Constants.PRODUCT_ANYID))) + userRole.Visible = false; - if (user.ID == m_user.ID) + // roleView + if (!(m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_OTHER, Constants.PRODUCT_ANYID)) && + !(hasRole && m_user.HasRight(Constants.RIGHTS_ROLE_VIEW_MY, Constants.PRODUCT_ANYID))) + roleView.Visible = false; + + List<Product> products = ProductDB.GetProductList(active); + foreach (Product product in products) { - userView.Visible = false; - userEdit.Visible = false; - userDelete.Visible = false; - foreach (Product product in products) + List<User> users = ProductDB.TCDB_GetProductUsers(product.ID,role.ID); + + if (users.Count > 0) { - if (!userView.Visible && m_user.HasRight("view_my_settings", product.ID)) - userView.Visible = true; - if (!userEdit.Visible && m_user.HasRight("edit_my_settings", product.ID)) - userEdit.Visible = true; + // roleEdit + if (!(m_user.HasRight(Constants.RIGHTS_ROLE_EDIT, product.ID)) && + !(hasRole && m_user.HasRight(Constants.RIGHTS_ROLE_EDIT_MY, product.ID))) + roleEdit.Visible = false; + + // roleDelete + if (!m_user.HasRight(Constants.RIGHTS_ROLE_DELETE, product.ID)) + roleDelete.Visible = false; } } - else - { - userView.Visible = false; - userEdit.Visible = false; - userDelete.Visible = true; - foreach (Product product in products) - { - if (!userView.Visible && m_user.HasRight("view_other_settings", user, product.ID)) - userView.Visible = true; - if (!userEdit.Visible && m_user.HasRight("edit_other_settings", user, product.ID)) - userEdit.Visible = true; - if (product.ID != Constants.PRODUCT_SITEID && user.HasRights(product.ID)) - { - if (userDelete.Visible && !m_user.HasRight("delete_user", product.ID)) - userDelete.Visible = false; - } - } - } - */ } protected void Product_Command(object sender, CommandEventArgs e) @@ -275,12 +254,24 @@ { int roleID = Convert.ToInt32(roleList.SelectedValue); - // TODO: Flush this out completely switch (e.CommandName) { + case "view": + Response.Redirect("~/Role.aspx?" + Constants.CODE_ROLE + "=" + roleID); + break; + case "edit": + Response.Redirect("~/Role.aspx?" + Constants.CODE_MODE + "=edit&" + Constants.CODE_ROLE + "=" + roleID); + break; + case "delete": + RightDB.DeleteRole(roleID); + Response.Redirect(Request.RawUrl); + break; case "new": - Response.Redirect("~/AdminRole.aspx"); + Response.Redirect("~/Role.aspx?" + Constants.CODE_MODE + "=new"); break; + case "user": + Response.Redirect("~/RoleAssignments.aspx?" + Constants.CODE_ROLE + "=" + roleID); + break; default: m_logg.Error("Invalid Command: " + e.CommandName); break; Modified: Website/Includes/UserRoles.ascx.cs =================================================================== --- Website/Includes/UserRoles.ascx.cs 2006-08-10 20:22:04 UTC (rev 304) +++ Website/Includes/UserRoles.ascx.cs 2006-08-10 21:11:42 UTC (rev 305) @@ -19,7 +19,7 @@ private static Logger m_logg = new Logger("TCDB.Code.UserRoles"); int roleID = Convert.ToInt32(HttpContext.Current.Request.QueryString[Constants.CODE_ROLE]); Role role; - String mode = HttpContext.Current.Request.QueryString["mode"]; + String mode = HttpContext.Current.Request.QueryString[Constants.CODE_MODE]; String productID = HttpContext.Current.Request.QueryString[Constants.CODE_PRODUCT]; protected void Page_Load(object sender, EventArgs e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |