Explorar el Código

update logic for determining first admin user

Alexander Belanger hace 3 años
padre
commit
c2fc1afeea
Se han modificado 1 ficheros con 13 adiciones y 4 borrados
  1. 13 4
      api/server/handlers/billing/redirect_billing.go

+ 13 - 4
api/server/handlers/billing/redirect_billing.go

@@ -50,18 +50,27 @@ func (c *RedirectBillingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 	user, _ := r.Context().Value(types.UserScope).(*models.User)
 	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 
+	if len(proj.Roles) == 0 {
+		http.Redirect(w, r, "/dashboard?error="+url.QueryEscape("Only the creator of the project can manage billing"), 302)
+		return
+	}
+
 	// at the moment, the user must be the first admin user on the project - otherwise, redirect back to
 	// home page with error
-	var isFirstAdminUser bool
+	var firstAdminRoleID uint = proj.Roles[0].ID
+	var currUserRoleID uint = 0
 
 	for _, role := range proj.Roles {
 		if role.UserID == user.ID && role.Kind == types.RoleAdmin {
-			isFirstAdminUser = true
-			break
+			currUserRoleID = role.ID
+		}
+
+		if role.Kind == types.RoleAdmin && role.ID <= firstAdminRoleID {
+			firstAdminRoleID = role.ID
 		}
 	}
 
-	if !isFirstAdminUser {
+	if currUserRoleID == 0 || currUserRoleID != firstAdminRoleID {
 		http.Redirect(w, r, "/dashboard?error="+url.QueryEscape("Only the creator of the project can manage billing"), 302)
 		return
 	}