Merge imbs -> dev
This commit is contained in:
commit
fe6942aa81
9 changed files with 257 additions and 20 deletions
|
@ -32,6 +32,7 @@ type Database interface {
|
|||
GetUserRole(username string, projectname string) (string, error)
|
||||
GetWeeklyReport(username string, projectName string, week int) (types.WeeklyReport, error)
|
||||
SignWeeklyReport(reportId int, projectManagerId int) error
|
||||
IsSiteAdmin(username string) (bool, error)
|
||||
}
|
||||
|
||||
// This struct is a wrapper type that holds the database connection
|
||||
|
@ -316,6 +317,26 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// IsSiteAdmin checks if a given username is a site admin
|
||||
func (d *Db) IsSiteAdmin(username string) (bool, error) {
|
||||
// Define the SQL query to check if the user is a site admin
|
||||
query := `
|
||||
SELECT COUNT(*) FROM site_admin
|
||||
JOIN users ON site_admin.admin_id = users.id
|
||||
WHERE users.username = ?
|
||||
`
|
||||
|
||||
// Execute the query
|
||||
var count int
|
||||
err := d.Get(&count, query, username)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// If count is greater than 0, the user is a site admin
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// Reads a directory of migration files and applies them to the database.
|
||||
// This will eventually be used on an embedded directory
|
||||
func (d *Db) Migrate() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue