|
|
@@ -164,6 +164,52 @@ func (app *App) HandleReadProjectPolicy(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// HandleUpdateProjectRole updates a project role with a new "kind"
|
|
|
+func (app *App) HandleUpdateProjectRole(w http.ResponseWriter, r *http.Request) {
|
|
|
+ id, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
+
|
|
|
+ if err != nil || id == 0 {
|
|
|
+ app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userID, err := strconv.ParseUint(chi.URLParam(r, "user_id"), 0, 64)
|
|
|
+
|
|
|
+ if err != nil || id == 0 {
|
|
|
+ app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ role, err := app.Repo.Project.ReadProjectRole(uint(id), uint(userID))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ form := &forms.UpdateProjectRoleForm{}
|
|
|
+
|
|
|
+ // decode from JSON to form value
|
|
|
+ if err := json.NewDecoder(r.Body).Decode(form); err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ role.Kind = form.Kind
|
|
|
+
|
|
|
+ role, err = app.Repo.Project.UpdateProjectRole(uint(id), role)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ app.handleErrorRead(err, ErrProjectDataRead, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := json.NewEncoder(w).Encode(role.Externalize()); err != nil {
|
|
|
+ app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// HandleDeleteProject deletes a project from the db, reading from the project_id
|
|
|
// in the URL param
|
|
|
func (app *App) HandleDeleteProject(w http.ResponseWriter, r *http.Request) {
|