Skip to content

Commit

Permalink
Merge pull request #94 from iandyh/revert
Browse files Browse the repository at this point in the history
Revert "Merge pull request #88 from iandyh/ownership"
  • Loading branch information
iandyh committed Oct 16, 2023
2 parents 1b4b5ff + f1ff888 commit 91f0542
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
8 changes: 4 additions & 4 deletions shibuya/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -492,7 +492,7 @@ func (s *ShibuyaAPI) collectionDeleteHandler(w http.ResponseWriter, r *http.Requ
}

func (s *ShibuyaAPI) collectionGetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
collection, err := checkCollectionOwnership(r, params)
collection, err := getCollection(params.ByName("collection_id"))
if err != nil {
s.handleErrors(w, err)
return
Expand Down Expand Up @@ -538,7 +538,7 @@ func (s *ShibuyaAPI) collectionUploadHandler(w http.ResponseWriter, r *http.Requ
s.handleErrors(w, makeInvalidResourceError("file"))
return
}
raw, err := io.ReadAll(file)
raw, err := ioutil.ReadAll(file)
if err != nil {
s.handleErrors(w, makeInvalidRequestError("invalid file"))
return
Expand Down Expand Up @@ -657,7 +657,7 @@ func (s *ShibuyaAPI) collectionDeploymentHandler(w http.ResponseWriter, r *http.
}

func (s *ShibuyaAPI) collectionTriggerHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
collection, err := checkCollectionOwnership(r, params)
collection, err := getCollection(params.ByName("collection_id"))
if err != nil {
s.handleErrors(w, err)
return
Expand Down
24 changes: 0 additions & 24 deletions shibuya/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package api
import (
"net/http"
"strings"

"github.com/julienschmidt/httprouter"
"github.com/rakutentech/shibuya/shibuya/model"
)

func retrieveClientIP(r *http.Request) string {
Expand All @@ -15,24 +12,3 @@ func retrieveClientIP(r *http.Request) string {
}
return strings.Split(t, ",")[0]
}

func checkCollectionOwnership(r *http.Request, params httprouter.Params) (*model.Collection, error) {
account := model.GetAccountBySession(r)
if account == nil {
return nil, makeLoginError()
}
collection, err := getCollection(params.ByName("collection_id"))
if err != nil {
return nil, err
}
project, err := model.GetProject(collection.ProjectID)
if err != nil {
return nil, err
}
if _, ok := account.MLMap[project.Owner]; !ok {
if !account.IsAdmin() {
return nil, makeNoPermissionErr("")
}
}
return collection, nil
}
11 changes: 0 additions & 11 deletions shibuya/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,3 @@ func GetAccountBySession(r *http.Request) *Account {
}
return a
}

func (a *Account) IsAdmin() bool {
for _, ml := range a.ML {
for _, admin := range config.SC.AuthConfig.AdminUsers {
if ml == admin {
return true
}
}
}
return false
}
11 changes: 10 additions & 1 deletion shibuya/ui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ func (u *UI) homeHandler(w http.ResponseWriter, r *http.Request, params httprout
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
IsAdmin := account.IsAdmin()
IsAdmin := false
outer:
for _, ml := range account.ML {
for _, admin := range config.SC.AuthConfig.AdminUsers {
if ml == admin {
IsAdmin = true
break outer
}
}
}
enableSid := config.SC.EnableSid
resultDashboardURL := config.SC.DashboardConfig.Url + config.SC.DashboardConfig.RunDashboard
engineHealthDashboardURL := config.SC.DashboardConfig.Url + config.SC.DashboardConfig.EnginesDashboard
Expand Down

0 comments on commit 91f0542

Please sign in to comment.