RemoveUserFromProject handler implemented, corresponding TS api, untested
This commit is contained in:
parent
76ae587116
commit
e67c54540c
4 changed files with 82 additions and 0 deletions
|
@ -17,6 +17,7 @@ type Database interface {
|
|||
AddUser(username string, password string) error
|
||||
CheckUser(username string, password string) bool
|
||||
RemoveUser(username string) error
|
||||
RemoveUserFromProject(username string, projectname string) error
|
||||
PromoteToAdmin(username string) error
|
||||
GetUserId(username string) (int, error)
|
||||
AddProject(name string, description string, username string) error
|
||||
|
@ -86,6 +87,10 @@ const isProjectManagerQuery = `SELECT COUNT(*) > 0 FROM user_roles
|
|||
JOIN projects ON user_roles.project_id = projects.id
|
||||
WHERE users.username = ? AND projects.name = ? AND user_roles.p_role = 'project_manager'`
|
||||
|
||||
const removeUserFromProjectQuery = `DELETE FROM user_roles
|
||||
WHERE user_id = (SELECT id FROM users WHERE username = ?)
|
||||
AND project_id = (SELECT id FROM projects WHERE name = ?)`
|
||||
|
||||
// DbConnect connects to the database
|
||||
func DbConnect(dbpath string) Database {
|
||||
// Open the database
|
||||
|
@ -147,6 +152,11 @@ func (d *Db) AddUserToProject(username string, projectname string, role string)
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Db) RemoveUserFromProject(username string, projectname string) error {
|
||||
_, err := d.Exec(removeUserFromProjectQuery, username, projectname)
|
||||
return err
|
||||
}
|
||||
|
||||
// ChangeUserRole changes the role of a user within a project.
|
||||
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
||||
// Execute the SQL query to change the user's role
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue