Skip to content

Commit

Permalink
Merge pull request #243 from IBM/subnet_filter
Browse files Browse the repository at this point in the history
Filter subnets when listing subnets, creating instance and ocp
  • Loading branch information
Catherine2019 authored Jan 18, 2021
2 parents 93dcb11 + 6ee3500 commit 5b4b60c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 51 deletions.
10 changes: 2 additions & 8 deletions web/clui/routes/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ func (v *InstanceView) New(c *macaron.Context, store session.Store) {
return
}
ctx := c.Req.Context()
_, subnets, err := subnetAdmin.List(ctx, 0, -1, "", "", "")
sql := fmt.Sprintf("type = 'public' or owner = %d", memberShip.OrgID)
_, subnets, err := subnetAdmin.List(ctx, 0, -1, "", "", sql)
if err != nil {
c.Data["ErrorMsg"] = err.Error()
c.HTML(500, "500")
Expand Down Expand Up @@ -1272,13 +1273,6 @@ func (v *InstanceView) Create(c *macaron.Context, store session.Store) {
c.HTML(http.StatusBadRequest, "error")
return
}
permit, err = memberShip.CheckAdmin(model.Writer, "subnets", int64(primaryID))
if !permit {
log.Println("Not authorized to access subnet")
c.Data["ErrorMsg"] = "Need Write permissions"
c.HTML(http.StatusBadRequest, "error")
return
}
primaryIP := c.QueryTrim("primaryip")
ipAddr := strings.Split(primaryIP, "/")[0]
primaryMac := c.QueryTrim("primarymac")
Expand Down
3 changes: 2 additions & 1 deletion web/clui/routes/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ func (v *OpenshiftView) New(c *macaron.Context, store session.Store) {
c.HTML(500, "500")
return
}
_, subnets, err := subnetAdmin.List(ctx, 0, -1, "", "", "")
sql := fmt.Sprintf("type = 'public' or owner = %d", memberShip.OrgID)
_, subnets, err := subnetAdmin.List(ctx, 0, -1, "", "", sql)
if err != nil {
c.Data["ErrorMsg"] = err.Error()
c.HTML(500, "500")
Expand Down
3 changes: 2 additions & 1 deletion web/clui/routes/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (a *SubnetAdmin) List(ctx context.Context, offset, limit int64, order, quer
where := ""
wm := memberShip.GetWhere()
if wm != "" {
where = fmt.Sprintf("type != 'internal' or %s", wm)
where = fmt.Sprintf("type = 'public' or %s", wm)
}
subnets = []*model.Subnet{}
if err = db.Model(&model.Subnet{}).Where(where).Where(query).Where(sql).Count(&total).Error; err != nil {
Expand Down Expand Up @@ -557,6 +557,7 @@ func (v *SubnetView) List(c *macaron.Context, store session.Store) {
c.Data["Total"] = total
c.Data["Pages"] = pages
c.Data["Query"] = query
c.Data["UserID"] = store.Get("uid").(int64)
if c.Req.Header.Get("X-Json-Format") == "yes" {
c.JSON(200, map[string]interface{}{
"subnets": subnets,
Expand Down
40 changes: 0 additions & 40 deletions web/clui/templates/instances_new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@

<div class="menu">

{{ if .IsAdmin }}

{{ range .Subnets }}

<div class="item" data-value={{.ID}} data-text={{.Name}}--{{.Network}}/{{.Netmask}}>
Expand All @@ -189,24 +187,6 @@

{{ end }}

{{ else }}

{{ range .Subnets }}

{{ if eq .Type "internal" }}

<div class="item" data-value={{.ID}} data-text={{.Name}}--{{.Network}}/{{.Netmask}}>

{{.Name}}

</div>

{{ end }}

{{ end }}

{{ end }}

</div>

</div>
Expand Down Expand Up @@ -243,8 +223,6 @@

<div class="menu">

{{ if .IsAdmin }}

{{ range .Subnets }}

<div class="item" data-value={{.ID}} data-text={{.Name}}--{{.Network}}/{{.Netmask}}>
Expand All @@ -255,24 +233,6 @@

{{ end }}

{{ else }}

{{ range .Subnets }}

{{ if eq .Type "internal" }}

<div class="item" data-value={{.ID}} data-text={{.Name}}--{{.Network}}/{{.Netmask}}>

{{.Name}}

</div>

{{ end }}

{{ end }}

{{ end }}

</div>

</div>
Expand Down
4 changes: 3 additions & 1 deletion web/clui/templates/subnets.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<tbody>
{{ $Link := .Link }}
{{ range .Subnets }}
{{ if or $.IsAdmin (eq $.UserID .Creater) }}
<tr>
{{ if $.IsAdmin }}
<td><a href="{{$Link}}/{{.ID}}">{{.ID}}</a></td>
Expand All @@ -65,7 +66,8 @@
{{ end }}
<td><div class="delete-button" data-url="{{$Link}}/{{.ID}}" data-id="{{.ID}}"><i class="dark purple trash alternate outline icon"></i></div></td>
</tr>
{{ end }}
{{ end }}
{{ end }}
</tbody>
</table>
</div>
Expand Down

0 comments on commit 5b4b60c

Please sign in to comment.