Skip to content
Snippets Groups Projects

Catchup with main 2.8.1

Merged Charlotte Hausman requested to merge catchup_with_main_2.8.1 into 2.8.2-DEVELOPMENT
55 files
+ 1606
623
Compare changes
  • Side-by-side
  • Inline
Files
55
@@ -26,9 +26,11 @@ import (
)
type UserInfo struct {
Name string
Email string
IsAod bool
Name string
Email string
Group string
IsUnavailable bool
IsAvailable bool
}
/**
@@ -46,8 +48,7 @@ func checkError(err error) {
/**
* Add a user to the qa_staff table in the database
*
* @param name a string with the name of the person to be added
* @param is_aod a bool to check if the user is an AOD or not
* @param user a UserInfo struct instance with the name, email, and stage of the person to be added
* @param db_info a DbInfo type with information to connect to the database
**/
func AddUser(user UserInfo, connectionInfo DbInfo) {
@@ -59,24 +60,74 @@ func AddUser(user UserInfo, connectionInfo DbInfo) {
checkError(err)
}(db)
group := "DA"
if user.IsAod {
group = "AOD"
}
// Add the user
// Add the user, new users are assumed to always be available
insertStatement := `insert into "qa_staff"("user_name", "group", "available", "email") values($1, $2, $3, $4)`
_, err := db.Exec(insertStatement, user.Name, group, true, user.Email)
_, err := db.Exec(insertStatement, user.Name, user.Group, true, user.Email)
checkError(err)
fmt.Println("Added " + user.Name + " to qa_staff")
fmt.Println("Updated " + user.Name + " to qa_staff")
}
//UpdateUser
/**
* Update existing user in the qa_staff table
*/
func UpdateUser(user UserInfo, connectionInfo DbInfo) {
// Get a connection to the database
db := GetConnection(connectionInfo)
defer func(db *sql.DB) {
err := db.Close()
checkError(err)
}(db)
// update the user
conditions := buildUpdateConditions(user)
updateStatement := `update qa_staff set ` + conditions + ` where user_name=$1`
_, err := db.Exec(updateStatement, user.Name)
checkError(err)
fmt.Println("Updated " + user.Name)
}
func buildUpdateConditions(user UserInfo) string {
// possible updatable field are email and available, changes in user groups should be new table entries
updateEmail := user.Email
updateUnavailability := user.IsUnavailable
updateAvailability := user.IsAvailable
//always set availability since we can't tell if it's actually being changed.
setCondition := ""
if updateEmail != "" {
setCondition = "email='" + user.Email + "'"
}
if updateUnavailability == true {
//user is now unavailable
if len(setCondition) > 0 {
// we are updating multiple fields
setCondition = setCondition + ", "
}
setCondition = setCondition + "available=false"
}
if updateAvailability == true {
//user is now available
if len(setCondition) > 0 {
// we are updating multiple fields
setCondition = setCondition + ", "
}
setCondition = setCondition + "available=true"
}
return setCondition
}
//RemoveUser
/**
* Remove a user from the qa_staff table in the database
*
* @param name a string with the name of the person to be removed
* @param user a UserInfo struct instance with the information of the person to be removed
* @param db_info a DbInfo type with information to connect to the database
**/
func RemoveUser(user UserInfo, connectionInfo DbInfo) {
@@ -89,9 +140,9 @@ func RemoveUser(user UserInfo, connectionInfo DbInfo) {
}(db)
// Remove the user
deleteStatement := `delete from "qa_staff" where "user_name"=$1`
_, err := db.Exec(deleteStatement, user.Name)
deleteStatement := `delete from "qa_staff" where "user_name"=$1 and "group"=$2`
_, err := db.Exec(deleteStatement, user.Name, user.Group)
checkError(err)
fmt.Println("Removed " + user.Name + " from qa_staff")
fmt.Println("Removed " + user.Name + ",group " + user.Group + " from qa_staff")
}
Loading