Skip to content

Commit dc1d4ff

Browse files
authored
feat: orgs integration with supertokens (#453)
* chore: enable organization routes with fixed custom roles references in storage * feat: CRUD org features * feat: passwordless invite based login to organization * feat: invite users and join through passwordless to specified org and roles * feat: add default role and permission to org joined user * feat: multi tenant supportinve roles and permissions * feat: enable creating and deleting teams in view * fix: display of team members in view * feat: enable removal and update of role from a user in an organization
1 parent 7c0d15a commit dc1d4ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1811
-676
lines changed

api/api/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"version": "v1",
55
"status": "active",
6-
"release_date": "2025-10-01T20:16:05.614781831+05:30",
6+
"release_date": "2025-10-04T21:33:19.645770465+05:30",
77
"end_of_life": "0001-01-01T00:00:00Z",
88
"changes": [
99
"Initial API version"

api/doc/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

api/go.mod

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ require (
7474
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
7575
github.com/creack/pty v1.1.24 // indirect
7676
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
77-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
7877
github.com/dgraph-io/badger v1.6.2 // indirect
7978
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
8079
github.com/dgraph-io/ristretto v0.2.0 // indirect
@@ -101,9 +100,9 @@ require (
101100
github.com/go-redis/redis_rate/v9 v9.1.2 // indirect
102101
github.com/go-sql-driver/mysql v1.9.3 // indirect
103102
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
104-
github.com/goccy/go-json v0.10.3 // indirect
105103
github.com/gogo/protobuf v1.3.2 // indirect
106104
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
105+
github.com/golang/mock v1.6.0 // indirect
107106
github.com/golang/protobuf v1.5.4 // indirect
108107
github.com/golang/snappy v1.0.0 // indirect
109108
github.com/google/cel-go v0.26.0 // indirect
@@ -130,12 +129,6 @@ require (
130129
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
131130
github.com/kr/fs v0.1.0 // indirect
132131
github.com/leodido/go-urn v1.4.0 // indirect
133-
github.com/lestrrat-go/blackmagic v1.0.3 // indirect
134-
github.com/lestrrat-go/httpcc v1.0.1 // indirect
135-
github.com/lestrrat-go/httprc v1.0.6 // indirect
136-
github.com/lestrrat-go/iter v1.0.2 // indirect
137-
github.com/lestrrat-go/jwx/v2 v2.1.6 // indirect
138-
github.com/lestrrat-go/option v1.0.1 // indirect
139132
github.com/libdns/libdns v1.1.1 // indirect
140133
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
141134
github.com/lunixbochs/vtclean v1.0.0 // indirect
@@ -159,6 +152,7 @@ require (
159152
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
160153
github.com/morikuni/aec v1.0.0 // indirect
161154
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
155+
github.com/nyaruka/phonenumbers v1.0.73 // indirect
162156
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
163157
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
164158
github.com/onsi/gomega v1.37.0 // indirect
@@ -180,7 +174,6 @@ require (
180174
github.com/rs/xid v1.6.0 // indirect
181175
github.com/russross/blackfriday/v2 v2.1.0 // indirect
182176
github.com/sagikazarmark/locafero v0.11.0 // indirect
183-
github.com/segmentio/asm v1.2.0 // indirect
184177
github.com/shoenig/go-m1cpu v0.1.6 // indirect
185178
github.com/shopspring/decimal v1.4.0 // indirect
186179
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
@@ -205,6 +198,7 @@ require (
205198
github.com/tklauser/go-sysconf v0.3.12 // indirect
206199
github.com/tklauser/numcpus v0.6.1 // indirect
207200
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
201+
github.com/twilio/twilio-go v0.26.0 // indirect
208202
github.com/urfave/cli v1.22.17 // indirect
209203
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
210204
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

api/go.sum

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,14 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
148148
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
149149
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
150150
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
151+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
151152
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
152153
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
153154
github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA=
154155
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
155156
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
156157
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
157158
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
158-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
159-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
160159
github.com/derekstavis/go-qs v0.0.0-20180720192143-9eef69e6c4e7 h1:zmAiXR9h1TCVN/0yCMRYQNE91dNRORpSzMFiqfTTPOs=
161160
github.com/derekstavis/go-qs v0.0.0-20180720192143-9eef69e6c4e7/go.mod h1:Vgz4nKcG6+B7QcALsWZpmhyQTLSl7nwFGKSrbq2LxEo=
162161
github.com/dgraph-io/badger v1.6.2 h1:mNw0qs90GVgGGWylh0umH5iag1j6n/PeJtNvL6KY/x8=
@@ -241,8 +240,6 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
241240
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
242241
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
243242
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
244-
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
245-
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
246243
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
247244
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
248245
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@@ -258,6 +255,7 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
258255
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
259256
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
260257
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
258+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
261259
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
262260
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
263261
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
@@ -394,18 +392,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
394392
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
395393
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
396394
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
397-
github.com/lestrrat-go/blackmagic v1.0.3 h1:94HXkVLxkZO9vJI/w2u1T0DAoprShFd13xtnSINtDWs=
398-
github.com/lestrrat-go/blackmagic v1.0.3/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw=
399-
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
400-
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
401-
github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k=
402-
github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
403-
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
404-
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
405-
github.com/lestrrat-go/jwx/v2 v2.1.6 h1:hxM1gfDILk/l5ylers6BX/Eq1m/pnxe9NBwW6lVfecA=
406-
github.com/lestrrat-go/jwx/v2 v2.1.6/go.mod h1:Y722kU5r/8mV7fYDifjug0r8FK8mZdw0K0GpJw/l8pU=
407-
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
408-
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
409395
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
410396
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
411397
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
@@ -538,8 +524,6 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
538524
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
539525
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
540526
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
541-
github.com/raghavyuva/caddygo v0.0.0-20250820132249-3db4bc273996 h1:vtCThL1ADhVV0f35qi9K3BnWCU34DGD8AS3TaP4ovjY=
542-
github.com/raghavyuva/caddygo v0.0.0-20250820132249-3db4bc273996/go.mod h1:nXAW//4ImRs0bC/UHcqsdYpif2YCvgFdxUAHE7JqdCc=
543527
github.com/raghavyuva/caddygo v0.0.0-20250919125030-03449d9e9252 h1:PCJiDfujvCXaHlhauvRo1aNEfbgAqfkbDBUsXa/TriU=
544528
github.com/raghavyuva/caddygo v0.0.0-20250919125030-03449d9e9252/go.mod h1:nXAW//4ImRs0bC/UHcqsdYpif2YCvgFdxUAHE7JqdCc=
545529
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
@@ -553,8 +537,6 @@ github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDc
553537
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
554538
github.com/schollz/jsonstore v1.1.0 h1:WZBDjgezFS34CHI+myb4s8GGpir3UMpy7vWoCeO0n6E=
555539
github.com/schollz/jsonstore v1.1.0/go.mod h1:15c6+9guw8vDRyozGjN3FoILt0wpruJk9Pi66vjaZfg=
556-
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
557-
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
558540
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
559541
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
560542
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
@@ -930,6 +912,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
930912
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
931913
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
932914
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
915+
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
933916
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
934917
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
935918
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

api/internal/features/auth/service/register.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ func (c *AuthService) Register(registrationRequest types.RegisterRequest, userTy
9393
}
9494
}
9595

96-
if registrationRequest.Organization != "" {
97-
requestedOrganization, err := c.organization_service.GetOrganization(registrationRequest.Organization)
98-
if err != nil {
99-
c.logger.Log(logger.Error, types.ErrFailedToGetOrganization.Error(), err.Error())
100-
return types.AuthResponse{}, types.ErrFailedToGetOrganization
101-
}
102-
103-
if err := c.addUserToOrganizationWithRole(user, requestedOrganization, userType, tx); err != nil {
104-
c.logger.Log(logger.Error, types.ErrFailedToAddUserToOrganization.Error(), err.Error())
105-
return types.AuthResponse{}, types.ErrFailedToAddUserToOrganization
106-
}
107-
}
96+
// if registrationRequest.Organization != "" {
97+
// requestedOrganization, err := c.organization_service.GetOrganization(registrationRequest.Organization)
98+
// if err != nil {
99+
// c.logger.Log(logger.Error, types.ErrFailedToGetOrganization.Error(), err.Error())
100+
// return types.AuthResponse{}, types.ErrFailedToGetOrganization
101+
// }
102+
103+
// if err := c.addUserToOrganizationWithRole(user, requestedOrganization, userType, tx); err != nil {
104+
// c.logger.Log(logger.Error, types.ErrFailedToAddUserToOrganization.Error(), err.Error())
105+
// return types.AuthResponse{}, types.ErrFailedToAddUserToOrganization
106+
// }
107+
// }
108108

109109
if err := tx.Commit(); err != nil {
110110
c.logger.Log(logger.Error, "failed to commit transaction", err.Error())
@@ -143,7 +143,6 @@ func (c *AuthService) addUserToOrganizationWithRole(user shared_types.User, orga
143143
userOrganization := organization_types.AddUserToOrganizationRequest{
144144
OrganizationID: organization.ID.String(),
145145
UserID: user.ID.String(),
146-
RoleId: roleName,
147146
}
148147

149148
return c.organization_service.AddUserToOrganization(userOrganization, tx)

api/internal/features/organization/controller/add_user_organization.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

api/internal/features/organization/controller/create_organization.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package controller
22

33
import (
4+
"fmt"
45
"net/http"
56

67
"github.com/go-fuego/fuego"
78
"github.com/raghavyuva/nixopus-api/internal/features/logger"
89
"github.com/raghavyuva/nixopus-api/internal/features/organization/types"
10+
"github.com/raghavyuva/nixopus-api/internal/features/supertokens"
911
"github.com/raghavyuva/nixopus-api/internal/utils"
1012

1113
shared_types "github.com/raghavyuva/nixopus-api/internal/types"
14+
"github.com/supertokens/supertokens-golang/recipe/userroles"
1215
)
1316

1417
func (c *OrganizationsController) CreateOrganization(f fuego.ContextWithBody[types.CreateOrganizationRequest]) (*shared_types.Response, error) {
@@ -50,9 +53,14 @@ func (c *OrganizationsController) CreateOrganization(f fuego.ContextWithBody[typ
5053
c.service.AddUserToOrganization(types.AddUserToOrganizationRequest{
5154
UserID: loggedInUser.ID.String(),
5255
OrganizationID: createdOrganization.ID.String(),
53-
RoleId: shared_types.RoleAdmin,
5456
})
5557

58+
// Create organization specific roles and assign admin role to the creator
59+
if err := c.createOrganizationRoles(createdOrganization.ID.String(), loggedInUser.SupertokensUserID); err != nil {
60+
c.logger.Log(logger.Error, "Failed to create organization roles", err.Error())
61+
// Don't fail the entire operation for role creation failure
62+
}
63+
5664
// c.Notify(notification.NortificationPayloadTypeCreateOrganization, loggedInUser, r, createdOrganization)
5765

5866
return &shared_types.Response{
@@ -61,3 +69,32 @@ func (c *OrganizationsController) CreateOrganization(f fuego.ContextWithBody[typ
6169
Data: createdOrganization,
6270
}, nil
6371
}
72+
73+
// createOrganizationRoles creates organization specific roles and assigns admin role to the creator
74+
func (c *OrganizationsController) createOrganizationRoles(organizationID, supertokensUserID string) error {
75+
// Create organization specific admin role
76+
adminRoleName := fmt.Sprintf("orgid_%s_admin", organizationID)
77+
if _, err := userroles.CreateNewRoleOrAddPermissions(adminRoleName, supertokens.GetAdminPermissions(), nil); err != nil {
78+
return fmt.Errorf("failed to create admin role %s: %w", adminRoleName, err)
79+
}
80+
81+
// Create organization specific member role
82+
memberRoleName := fmt.Sprintf("orgid_%s_member", organizationID)
83+
if _, err := userroles.CreateNewRoleOrAddPermissions(memberRoleName, supertokens.GetMemberPermissions(), nil); err != nil {
84+
return fmt.Errorf("failed to create member role %s: %w", memberRoleName, err)
85+
}
86+
87+
// Create organization specific viewer role
88+
viewerRoleName := fmt.Sprintf("orgid_%s_viewer", organizationID)
89+
if _, err := userroles.CreateNewRoleOrAddPermissions(viewerRoleName, supertokens.GetViewerPermissions(), nil); err != nil {
90+
return fmt.Errorf("failed to create viewer role %s: %w", viewerRoleName, err)
91+
}
92+
93+
// Assign admin role to the organization creator
94+
if _, err := userroles.AddRoleToUser("public", supertokensUserID, adminRoleName, nil); err != nil {
95+
return fmt.Errorf("failed to assign admin role %s to user %s: %w", adminRoleName, supertokensUserID, err)
96+
}
97+
98+
c.logger.Log(logger.Info, "Successfully created organization roles", organizationID)
99+
return nil
100+
}

api/internal/features/organization/controller/get_organization_users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (c *OrganizationsController) GetOrganizationUsers(f fuego.ContextWithBody[G
2323
Status: http.StatusBadRequest,
2424
}
2525
}
26-
users, err := c.service.GetOrganizationUsers(id)
26+
users, err := c.service.GetOrganizationUsersWithRoles(id)
2727
if err != nil {
2828
return nil, fuego.HTTPError{
2929
Err: err,

api/internal/features/organization/controller/get_resources.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

api/internal/features/organization/controller/get_roles.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)