///*********************** GROUPS **************************/// /// <summary> /// Creates the group GroupName in the Service Broker user/group namespace. /// </summary> /// <param name="groupName">A string to be used in adminstrative listings to identify the group on the Service Broker. Must be unique in a namespace shared with User instances.</param> /// <param name="parentGroupID">The ID of the new group’s parent group. If less than or equal to 0, the new group is created as a top level group parented off the root of the group hierarchy.</param> /// <param name="description">A brief description of the Group suitable for display in a table or a GUI.</param> /// <param name="email">The contact email for group administration.</param> /// <returns>The unique groupID which identifies this group internally to the Service Broker.>0 if the group was unknown and was successfully registered; ==-1 otherwise.</returns> /// <remarks>The method will first create the group in the agents table & /// then create an entry in the groups table (using the agentID). /// Then it will create a group qualifier and an experiment collection qualifier associated with the group /// </remarks> public static int AddGroup(string groupName, int parentGroupID, string description, string email, string groupType, int associatedGroupID) { Group g = new Group (); g.groupName = groupName; g.description = description; g.email=email; g.groupType=groupType; int RootGroupID = GetGroupID (Group.ROOT); int parentQualifierID = Qualifier.ROOT; int parentECQualifierID = Qualifier.ROOT; // If the parent group ID is <=0 then the default parent group is ROOT (ROOT groupID = 1) if (parentGroupID <=0) parentGroupID = RootGroupID; // If the parent Group is not ROOT then get its qualifierIDs (otherwise the parentQualifier is just Root) if (parentGroupID != RootGroupID) { parentQualifierID = Authorization.AuthorizationAPI.GetQualifierID(parentGroupID, Qualifier.groupQualifierTypeID); //Request groups are added to new user group (which doesn't have an experiment collection) int NewUserGroupID = GetGroupID (Group.NEWUSERGROUP); if (parentGroupID != NewUserGroupID) { parentECQualifierID = Authorization.AuthorizationAPI.GetQualifierID(parentGroupID,Qualifier.experimentCollectionQualifierTypeID); } } try { // Add group to database //Inserts agents too. See InternalDB method for details. g.groupID = InternalAdminDB.InsertGroup(g,parentGroupID, associatedGroupID); try { // add into Qualifier table as well as Q-H table if (parentQualifierID >0) Authorization.AuthorizationAPI .AddQualifier (g.groupID, Authorization.Qualifier .groupQualifierTypeID , g.groupName, parentQualifierID); // Only insert experiment collection Qualifier for regular groups if (parentECQualifierID >0 && (groupType.CompareTo(GroupType.REGULAR) == 0)) Authorization.AuthorizationAPI.AddQualifier(g.groupID,Authorization.Qualifier.experimentCollectionQualifierTypeID,g.groupName+ " Experiment Collection",parentECQualifierID); } catch (Exception ex) { // rollback group insertion InternalAdminDB.DeleteGroups(new int[]{g.groupID}); throw; } } catch (Exception ex) { throw; } return g.groupID; }
private void PageRedirect(Group effectiveGroup) { // initialize boolean session variables that indicate what type of effective group this is Session["IsAdmin"] = false; Session["IsServiceAdmin"] = false; if((effectiveGroup.groupName.Equals(Group.SUPERUSER))||(effectiveGroup.groupType.Equals(GroupType.COURSE_STAFF))) { Session["IsAdmin"] = true; Response.Redirect ("admin/manageUsers.aspx"); } // if the effective group is a service admin group, then redirect to the service admin page. // the session variable is used in the userNav page to check whether to make the corresponing tab visible else if (effectiveGroup.groupType.Equals(GroupType.SERVICE_ADMIN)) { Session["IsServiceAdmin"] = true; Response.Redirect ("admin/adminServices.aspx"); } else { Session["IsAdmin"] = false; Session["IsServiceAdmin"] = false; Response.Redirect ("myLabs.aspx"); } }
private void displayGroup(Group gp) { txtName.Text = gp.GroupName; groupInfo.name = gp.GroupName; groupInfo.id=gp.groupID; txtDescription.Text = gp.description ; groupInfo.description = gp.description ; if(groupInfo.id > 0) { txtName.ReadOnly = true; txtEmail.Text = gp.email; groupInfo.email =gp.email; // Check for a request group int request = AdministrativeUtilities.GetGroupRequestGroup(groupInfo.id); if(request > 0) { Group [] requestGroup = wrapper.GetGroupsWrapper(new int [] {request}); if(requestGroup.Length > 0) { groupInfo.request = requestGroup[0].groupID; cbxRequestgroup.Checked = true; txtRequestgroup.Text = requestGroup[0].GroupName.ToString(); txtRequestgroup.Visible=true; } else { cbxRequestgroup.Checked = false; } } // Check for a TA group int TAGrp = AdministrativeUtilities.GetGroupAdminGroup(groupInfo.id); if(TAGrp > 0) { Group [] TAGroup = wrapper.GetGroupsWrapper(new int [] {TAGrp}); if(TAGroup.Length > 0) { groupInfo.admin = TAGroup[0].groupID; cbxTAGroup.Checked = true; txtTAGroup.Text = TAGroup[0].GroupName.ToString(); txtTAGroup.Visible=true; } else { cbxTAGroup.Checked = false; } } int qualId = AuthorizationAPI.GetQualifierID(groupInfo.id,Qualifier.experimentCollectionQualifierTypeID); if(qualId >0) { groupInfo.collectionNode = qualId; showExpGrants=true; getExpGrants(); repExperiments.DataSource = expGrants; repExperiments.DataBind(); } // find parents parentIDs = InternalAuthorizationDB.ListAgentParentsFromDS(gp.GroupID); loadParentLists(); } //list lab clients int[] clientIDs = AdministrativeUtilities.GetGroupLabClients(gp.groupID); if (clientIDs.Length>0) { LabClient[] clients = wrapper.GetLabClientsWrapper(clientIDs); repLabClients.DataSource = clients; repLabClients.DataBind(); showAssocLabClients = true; } }
// Will probably need new methods for user sessions by group and by time /* !------------------------------------------------------------------------------! * CALLS FOR GROUPS * !------------------------------------------------------------------------------! */ /// <summary> /// to add a group /// </summary> public static int InsertGroup(Group grp, int parentGroupID, int associatedGroupID) { // The Add Group stored procedure first inserts a group into the Agents table //& then Agent Hierarchy, with the specified parent group id // The AgentID is then used as the primary key in the groups table // Corresponding qualifiers are NOT added here since they // usually only created after the actual group record has been created int groupID = -1; DbConnection myConnection = FactoryDB.GetConnection(); DbCommand myCommand = FactoryDB.CreateCommand("Group_Insert", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add(FactoryDB.CreateParameter("@groupName", grp.groupName,DbType.String,256)); myCommand.Parameters.Add(FactoryDB.CreateParameter("@description", grp.description,DbType.String,2048)); myCommand.Parameters.Add(FactoryDB.CreateParameter("@email", grp.email,DbType.String,256)); myCommand.Parameters.Add(FactoryDB.CreateParameter("@parentGroupID",parentGroupID,DbType.Int32)); myCommand.Parameters.Add(FactoryDB.CreateParameter("@groupType", grp.groupType,DbType.AnsiString,100)); myCommand.Parameters.Add(FactoryDB.CreateParameter( "@associatedGroupID", associatedGroupID, DbType.Int32)); try { myConnection.Open(); groupID = Int32.Parse ( myCommand.ExecuteScalar().ToString ()); } catch (Exception ex) { throw new Exception("Exception thrown in inserting group",ex); } finally { myConnection.Close(); } // refresh A & A-H in memory AuthCache.AgentsSet = InternalAuthorizationDB.RetrieveAgents(); AuthCache.AgentHierarchySet = InternalAdminDB.RetrieveGroupHierarchy(); return groupID; }
/// <summary> /// Modifies the description of the group groupID in the Service Broker User/Group namespace. /// </summary> /// <param name="groupID">The ID of the group whose description will be modified.</param> /// <param name="groupName">A string to be used in administrative listings to identify the group on the Service Broker; If NULL, then the previous value will not be changed.</param> /// <param name="description">The new brief description of the Group suitable for display in a table or a GUI.</param> /// <param name="email">The new email contact for Group administration; if NULL, then the previous value will not be changed.</param> public static void ModifyGroup(int groupID,string groupName, string description, string email) { Group g = new Group (); g.groupID = groupID; g.groupName = groupName; g.description = description; g.email = email; try { InternalAdminDB.UpdateGroup (g); } catch (Exception ex) { throw; } }
protected static Group readGroup(DbDataReader reader) { // select g.Group_ID, g.Group_Type_ID,g.Associated_Group_ID, g.Date_Created, g.group_name, // g.description AS description, g.email, gt.description AS group_type Group grp = new Group(); grp.groupID = reader.GetInt32(0); grp.groupTypeID = reader.GetInt32(1); grp.associatedGroupID = reader.GetInt32(2); grp.createTime = DateUtil.SpecifyUTC(reader.GetDateTime(3)); grp.groupName = reader.GetString(4); if(!reader.IsDBNull(5)) grp.description = reader.GetString(5); if (!reader.IsDBNull(6)) grp.email = reader.GetString(6); grp.groupType = reader.GetString(7); return grp; }
/// <summary> /// to modify a group /// </summary> public static void UpdateGroup(Group grp) { DbConnection myConnection = FactoryDB.GetConnection(); DbCommand myCommand = FactoryDB.CreateCommand("Group_Update", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add(FactoryDB.CreateParameter( "@groupID", grp.groupID, DbType.Int32)); myCommand.Parameters.Add(FactoryDB.CreateParameter( "@groupName", grp.groupName, DbType.String,256)); myCommand.Parameters.Add(FactoryDB.CreateParameter( "@description", grp.description, DbType.String, 2048)); myCommand.Parameters.Add(FactoryDB.CreateParameter( "@email", grp.email, DbType.String, 256)); try { myConnection.Open(); int i = myCommand.ExecuteNonQuery(); if(i == 0) throw new Exception ("No record modified exception"); } catch (Exception ex) { throw new Exception("Exception thrown in modifying group",ex); } finally { myConnection.Close(); } }
private bool isRegular(Group g) { return (g.groupTypeID == 1); }
private void PageRedirect(Group effectiveGroup) { // initialize boolean session variables that indicate what type of effective group this is Session["IsAdmin"] = false; Session["IsServiceAdmin"] = false; Session["GroupID"] = effectiveGroup.groupID; Session["GroupName"] = effectiveGroup.groupName; Session["GroupCount"] = 1; int client = 0; if (Session["ClientID"] != null) client = Convert.ToInt32(Session["ClientID"]); AdministrativeAPI.ModifyUserSession(Convert.ToInt64(Session["SessionID"]), effectiveGroup.groupID, client, Session.SessionID); if((effectiveGroup.groupName.Equals(Group.SUPERUSER))||(effectiveGroup.groupType.Equals(GroupType.COURSE_STAFF))) { Session["IsAdmin"] = true; Response.Redirect ("admin/manageUsers.aspx"); } // if the effective group is a service admin group, then redirect to the service admin page. // the session variable is used in the userNav page to check whether to make the corresponing tab visible else if (effectiveGroup.groupType.Equals(GroupType.SERVICE_ADMIN)) { Session["IsServiceAdmin"] = true; Response.Redirect ("admin/adminServices.aspx"); } else { Session["IsAdmin"] = false; Session["IsServiceAdmin"] = false; Response.Redirect ("myLabs.aspx"); } }
/// <summary> /// to retrieve group metadata for groups specified by array of group IDs /// </summary> public static Group[] SelectGroups( int[] groupIDs ) { Group[] g = new Group[groupIDs.Length ]; for (int i=0; i<groupIDs.Length ; i++) { g[i] = new Group(); } DbConnection myConnection = FactoryDB.GetConnection(); DbCommand myCommand = FactoryDB.CreateCommand("RetrieveGroup", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters .Add(FactoryDB.CreateParameter(myCommand,"@groupID",null,DbType.Int32)); try { myConnection.Open (); for (int i =0; i < groupIDs.Length ; i++) { myCommand.Parameters["@groupID"].Value = groupIDs[i]; // get labserver info from table lab_servers DbDataReader myReader = myCommand.ExecuteReader (); while(myReader.Read ()) { g[i].groupID = groupIDs[i]; if(myReader["group_name"] != System.DBNull.Value ) g[i].groupName= (string) myReader["group_name"]; if(myReader["description"] != System.DBNull.Value ) g[i].description= (string) myReader["description"]; if(myReader["email"] != System.DBNull.Value ) g[i].email= (string) myReader["email"]; if(myReader["group_type"] != System.DBNull.Value ) g[i].groupType= (string) myReader["group_type"]; /*if(myReader["date_created"] != System.DBNull .Value ) g[i].= (string) myReader["date_created"];*/ } myReader.Close (); } } catch (Exception ex) { throw new Exception("Exception thrown SelectGroups",ex); } finally { myConnection.Close (); } return g; }