Skip to content

Commit

Permalink
wip: display teams
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jun 17, 2024
1 parent 90e5473 commit b0aca13
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 153 deletions.
6 changes: 3 additions & 3 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"log"
"os"

"github.com/zeiss/fiber-goth/adapters"
"github.com/zeiss/service-lens/internal/adapters/db"
"github.com/zeiss/service-lens/internal/configs"
"github.com/zeiss/service-lens/internal/models"
"github.com/zeiss/service-lens/internal/utils"

"github.com/katallaxie/pkg/logger"
"github.com/spf13/cobra"
Expand All @@ -22,11 +22,11 @@ var seeds = []seed.Seed{
{
Name: "create teams",
Run: func(db *gorm.DB) error {
return db.Create([]models.Team{
return db.Create([]adapters.GothTeam{
{
Name: "Super Admins",
Slug: "superadmins",
Description: utils.StrPtr("Super Admins have access to all features and can manage all resources."),
Description: "Super Admins have access to all features and can manage all resources.",
},
}).Error
},
Expand Down
6 changes: 1 addition & 5 deletions cmd/server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/zeiss/fiber-goth/providers/github"
"github.com/zeiss/service-lens/internal/adapters/db"
"github.com/zeiss/service-lens/internal/adapters/handlers"
"github.com/zeiss/service-lens/internal/utils"

"github.com/gofiber/fiber/v2"
logger "github.com/gofiber/fiber/v2/middleware/logger"
Expand Down Expand Up @@ -98,9 +97,6 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
Adapter: gorm,
Secret: goth.GenerateKey(),
CookieHTTPOnly: true,
ResponseFilter: func(c *fiber.Ctx) error {
return c.Redirect("/")
},
}

handlers := handlers.New(store)
Expand All @@ -125,7 +121,7 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
site.Get("/teams/:id", handlers.ShowTeam())

// Team ...
team := app.Group("/teams/:t_slug", utils.ResolveTeam(conn))
team := app.Group("/teams/:t_slug")

team.Get("/profiles", handlers.ListProfiles())
team.Get("/profiles/new", handlers.NewProfile())
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.1
github.com/zeiss/fiber-authz v1.0.27
github.com/zeiss/fiber-goth v1.2.1
github.com/zeiss/fiber-htmx v1.3.13-0.20240610074751-3a512b2b7530
github.com/zeiss/fiber-goth v1.2.5-0.20240617202320-5c9e19c3cac1
github.com/zeiss/fiber-htmx v1.3.14-0.20240617201626-08cb677ed1b1
github.com/zeiss/gorm-seed v0.1.0
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
Expand Down Expand Up @@ -123,7 +123,7 @@ require (
github.com/karamaru-alpha/copyloopvar v1.1.0 // indirect
github.com/kisielk/errcheck v1.7.0 // indirect
github.com/kkHAIKE/contextcheck v1.1.5 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kulti/thelper v0.6.3 // indirect
github.com/kunwardeep/paralleltest v1.0.10 // indirect
github.com/kyoh86/exportloopref v0.1.11 // indirect
Expand Down Expand Up @@ -210,7 +210,7 @@ require (
github.com/ultraware/whitespace v0.1.1 // indirect
github.com/uudashr/gocognit v1.1.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.54.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xen0n/gosmopolitan v1.2.2 // indirect
github.com/yagipy/maintidx v1.0.0 // indirect
Expand All @@ -223,11 +223,11 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ github.com/kisielk/errcheck v1.7.0 h1:+SbscKmWJ5mOK/bO1zS60F5I9WwZDWOfRsC4RwfwRV
github.com/kisielk/errcheck v1.7.0/go.mod h1:1kLL+jV4e+CFfueBmI1dSK2ADDyQnlrnrY/FqKluHJQ=
github.com/kkHAIKE/contextcheck v1.1.5 h1:CdnJh63tcDe53vG+RebdpdXJTc9atMgGqdx8LXxiilg=
github.com/kkHAIKE/contextcheck v1.1.5/go.mod h1:O930cpht4xb1YQpK+1+AgoM3mFsvxr7uyFptcnWTYUA=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -471,8 +471,8 @@ github.com/uudashr/gocognit v1.1.2 h1:l6BAEKJqQH2UpKAPKdMfZf5kE4W/2xk8pfU1OVLvni
github.com/uudashr/gocognit v1.1.2/go.mod h1:aAVdLURqcanke8h3vg35BC++eseDm66Z7KmchI5et4k=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0=
github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU=
Expand All @@ -491,10 +491,12 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zeiss/fiber-authz v1.0.27 h1:vm8oorWm2Kj8LG34mI68I1tFL5DB/Qk4vNRmP1lynCs=
github.com/zeiss/fiber-authz v1.0.27/go.mod h1:wC7CT4M+oLTQMhwZLbKZDAqSYBcla967jpOC+fwMf2c=
github.com/zeiss/fiber-goth v1.2.1 h1:mXjQx5ekV6jfe3Gi0apyTGh2IoQ8zRw2oY1o8iy+CmQ=
github.com/zeiss/fiber-goth v1.2.1/go.mod h1:AVhqrCUdrqRdtu+N0mkq/JI2rZd01Ss46LKbdXZ3bsA=
github.com/zeiss/fiber-htmx v1.3.13-0.20240610074751-3a512b2b7530 h1:bpNvCu3lLjDqIG6Sjs4IlCF+/iCXhT1dMoKNUrhd978=
github.com/zeiss/fiber-htmx v1.3.13-0.20240610074751-3a512b2b7530/go.mod h1:wrImAwUwanaWa1lzams1VQpEfKhtxHuW0yjLffMrk0w=
github.com/zeiss/fiber-goth v1.2.4 h1:tzuS4iXhCC9elEzVNVKILB4fBMa+wkaSqe8kr6jLA4c=
github.com/zeiss/fiber-goth v1.2.4/go.mod h1:TkapFI+7LOvbb093zF8cP/CH2PcQJSBQWQZDzgGoygE=
github.com/zeiss/fiber-goth v1.2.5-0.20240617202320-5c9e19c3cac1 h1:remNQlG6mqdgCBM2CejZ4rsdY8/waXQ90iCSowNLCfw=
github.com/zeiss/fiber-goth v1.2.5-0.20240617202320-5c9e19c3cac1/go.mod h1:TkapFI+7LOvbb093zF8cP/CH2PcQJSBQWQZDzgGoygE=
github.com/zeiss/fiber-htmx v1.3.14-0.20240617201626-08cb677ed1b1 h1:lGyS9adJc1CozNEgMvshzXBfvp3DMDeduWuZPAhl9fk=
github.com/zeiss/fiber-htmx v1.3.14-0.20240617201626-08cb677ed1b1/go.mod h1:SvNPGf7l72gG1rAW++gan7QNkJc/8tKWqyMStUqUpgM=
github.com/zeiss/gorm-seed v0.1.0 h1:0pdXHyytd30Bv8dasssWQzVo80d7RpvB0M8uZRdevCc=
github.com/zeiss/gorm-seed v0.1.0/go.mod h1:Tli6ekFpRjtQY8S6VoNiLgRnX1DVEvHJkf+UI85kV+E=
gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo=
Expand Down Expand Up @@ -522,8 +524,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f h1:phY1HzDcf18Aq9A8KkmRtY9WvOFIxN8wgfvy6Zm1DV8=
Expand Down Expand Up @@ -558,8 +560,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
12 changes: 6 additions & 6 deletions internal/adapters/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func (d *database) Migrate(ctx context.Context) error {
&adapters.GothAccount{},
&adapters.GothSession{},
&adapters.GothVerificationToken{},
&adapters.GothTeam{},
&models.ProfileQuestion{},
&models.ProfileQuestionChoice{},
&models.ProfileQuestionAnswer{},
&models.Team{},
&models.Environment{},
&models.Profile{},
&models.Lens{},
Expand Down Expand Up @@ -270,26 +270,26 @@ func (t *datastoreTx) GetWorkloadAnswer(ctx context.Context, answer *models.Work
}

// GetTeam is a method that returns a team by ID
func (t *datastoreTx) GetTeam(ctx context.Context, team *models.Team) error {
func (t *datastoreTx) GetTeam(ctx context.Context, team *adapters.GothTeam) error {
return t.tx.First(team).Error
}

// ListTeams is a method that returns a list of teams
func (t *datastoreTx) ListTeams(ctx context.Context, pagination *tables.Results[models.Team]) error {
func (t *datastoreTx) ListTeams(ctx context.Context, pagination *tables.Results[adapters.GothTeam]) error {
return t.tx.Scopes(tables.PaginatedResults(&pagination.Rows, pagination, t.tx)).Find(&pagination.Rows).Error
}

// CreateTeam is a method that creates a team
func (t *datastoreTx) CreateTeam(ctx context.Context, team *models.Team) error {
func (t *datastoreTx) CreateTeam(ctx context.Context, team *adapters.GothTeam) error {
return t.tx.Create(team).Error
}

// UpdateTeam is a method that updates a team
func (t *datastoreTx) UpdateTeam(ctx context.Context, team *models.Team) error {
func (t *datastoreTx) UpdateTeam(ctx context.Context, team *adapters.GothTeam) error {
return t.tx.Session(&gorm.Session{FullSaveAssociations: true}).Save(team).Error
}

// DeleteTeam is a method that deletes a team
func (t *datastoreTx) DeleteTeam(ctx context.Context, team *models.Team) error {
func (t *datastoreTx) DeleteTeam(ctx context.Context, team *adapters.GothTeam) error {
return t.tx.Delete(team).Error
}
31 changes: 17 additions & 14 deletions internal/components/account-switcher.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package components

import (
"fmt"

"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/dividers"
"github.com/zeiss/fiber-htmx/components/dropdowns"
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/links"
"github.com/zeiss/fiber-htmx/components/utils"
)

// AccountSwitcherProps ...
Expand Down Expand Up @@ -40,20 +43,20 @@ func AccountSwitcher(props AccountSwitcherProps, children ...htmx.Node) htmx.Nod
"w-full": true,
},
},
// utils.Map(func(el authz.Team) htmx.Node {
// return dropdowns.DropdownMenuItem(
// dropdowns.DropdownMenuItemProps{},
// links.Link(
// links.LinkProps{
// ClassNames: htmx.ClassNames{
// "link": false,
// },
// Href: fmt.Sprintf("/teams/%s/index", el.Slug),
// },
// htmx.Text(el.Name),
// ),
// )
// }, *props.User.Teams...),
utils.Map(func(el adapters.GothTeam) htmx.Node {
return dropdowns.DropdownMenuItem(
dropdowns.DropdownMenuItemProps{},
links.Link(
links.LinkProps{
ClassNames: htmx.ClassNames{
"link": false,
},
Href: fmt.Sprintf("/teams/%s", el.Slug),
},
htmx.Text(el.Name),
),
)
}, *props.User.Teams...),
dividers.Divider(
dividers.DividerProps{
ClassNames: htmx.ClassNames{},
Expand Down
1 change: 0 additions & 1 deletion internal/components/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type LayoutProps struct {
Children []htmx.Node
User adapters.GothUser
Path string
Team string
}

// WrapProps ...
Expand Down
29 changes: 23 additions & 6 deletions internal/components/teams/teams-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package teams
import (
"fmt"

"github.com/zeiss/fiber-goth/adapters"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/forms"
"github.com/zeiss/fiber-htmx/components/links"
"github.com/zeiss/fiber-htmx/components/tables"
"github.com/zeiss/service-lens/internal/models"
)

const (
Expand All @@ -17,7 +17,7 @@ const (

// TeamsTableProps ...
type TeamsTableProps struct {
Teams []*models.Team
Teams []*adapters.GothTeam
Offset int
Limit int
Total int
Expand Down Expand Up @@ -105,14 +105,14 @@ func TeamsTable(props TeamsTableProps, children ...htmx.Node) htmx.Node {
),
),
},
[]tables.ColumnDef[*models.Team]{
[]tables.ColumnDef[*adapters.GothTeam]{
{
ID: "id",
AccessorKey: "id",
Header: func(p tables.TableProps) htmx.Node {
return htmx.Th(htmx.Text("ID"))
},
Cell: func(p tables.TableProps, row *models.Team) htmx.Node {
Cell: func(p tables.TableProps, row *adapters.GothTeam) htmx.Node {
return htmx.Td(
htmx.Text(row.ID.String()),
)
Expand All @@ -124,7 +124,7 @@ func TeamsTable(props TeamsTableProps, children ...htmx.Node) htmx.Node {
Header: func(p tables.TableProps) htmx.Node {
return htmx.Th(htmx.Text("Name"))
},
Cell: func(p tables.TableProps, row *models.Team) htmx.Node {
Cell: func(p tables.TableProps, row *adapters.GothTeam) htmx.Node {
return htmx.Td(
links.Link(
links.LinkProps{
Expand All @@ -135,11 +135,28 @@ func TeamsTable(props TeamsTableProps, children ...htmx.Node) htmx.Node {
)
},
},
{
ID: "slug",
AccessorKey: "slug",
Header: func(p tables.TableProps) htmx.Node {
return htmx.Th(htmx.Text("Slug"))
},
Cell: func(p tables.TableProps, row *adapters.GothTeam) htmx.Node {
return htmx.Td(
links.Link(
links.LinkProps{
Href: fmt.Sprintf(showTeamURL, row.ID),
},
htmx.Text(row.Slug),
),
)
},
},
{
Header: func(p tables.TableProps) htmx.Node {
return nil
},
Cell: func(p tables.TableProps, row *models.Team) htmx.Node {
Cell: func(p tables.TableProps, row *adapters.GothTeam) htmx.Node {
return htmx.Td(
buttons.Button(
buttons.ButtonProps{
Expand Down
14 changes: 10 additions & 4 deletions internal/controllers/profiles/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

goth "github.com/zeiss/fiber-goth"
"github.com/zeiss/fiber-goth/adapters"
"github.com/zeiss/service-lens/internal/models"
"github.com/zeiss/service-lens/internal/ports"
"github.com/zeiss/service-lens/internal/utils"

"github.com/go-playground/validator/v10"
htmx "github.com/zeiss/fiber-htmx"
Expand All @@ -22,6 +23,7 @@ var validate *validator.Validate
type CreateProfileControllerImpl struct {
profile models.Profile
store ports.Datastore
team adapters.GothTeam
htmx.DefaultController
}

Expand Down Expand Up @@ -49,8 +51,12 @@ func (l *CreateProfileControllerImpl) Prepare() error {
return err
}

team := utils.FromContextTeam(l.Ctx())
l.profile.TeamID = team.ID
session, err := goth.SessionFromContext(l.Ctx())
if err != nil {
return err
}
l.profile.TeamID = session.User.TeamBySlug(l.Ctx().Params("t_slug")).ID
l.team = session.User.TeamBySlug(l.Ctx().Params("t_slug"))

err = validate.Struct(&l.profile)
if err != nil {
Expand All @@ -64,5 +70,5 @@ func (l *CreateProfileControllerImpl) Prepare() error {

// Post ...
func (l *CreateProfileControllerImpl) Post() error {
return l.Redirect(fmt.Sprintf(listProfilesURL, utils.FromContextTeam(l.Ctx()).Slug))
return l.Redirect(fmt.Sprintf(listProfilesURL, l.team.ID))
}
Loading

0 comments on commit b0aca13

Please sign in to comment.