Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

add migration and tenant to jwt claims

goenningd4ae2bd5d961
diff --git a/app/feedback/handler.go b/app/feedback/handler.go
index f59ad8a1f..940b286a3 100644
--- a/app/feedback/handler.go
+++ b/app/feedback/handler.go
@@ -3,8 +3,6 @@ package feedback
import (
"strings"
- "fmt"
-
"github.com/WeCanHearYou/wechy/app"
"github.com/labstack/echo"
)
@@ -46,8 +44,6 @@ func (h AllHandlers) PostIdea() app.HandlerFunc {
return c.Failure(err)
}
- fmt.Println(input)
-
if strings.Trim(input.Title, " ") == "" {
return c.JSON(400, echo.Map{
"message": "Idea title is required.",
diff --git a/app/identity/jwt_test.go b/app/identity/jwt_test.go
index 19a540fae..6b741101e 100644
--- a/app/identity/jwt_test.go
+++ b/app/identity/jwt_test.go
@@ -29,6 +29,7 @@ func TestJWT_Decode(t *testing.T) {
UserID: 424,
UserName: "Jon Snow",
UserEmail: "[email protected]",
+ TenantID: 2,
}
token, _ := identity.Encode(claims)
@@ -38,4 +39,5 @@ func TestJWT_Decode(t *testing.T) {
Expect(decoded.UserID).To(Equal(claims.UserID))
Expect(decoded.UserName).To(Equal(claims.UserName))
Expect(decoded.UserEmail).To(Equal(claims.UserEmail))
+ Expect(decoded.TenantID).To(Equal(claims.TenantID))
}
diff --git a/app/model.go b/app/model.go
index 06be5ab1b..e88ae7b0a 100644
--- a/app/model.go
+++ b/app/model.go
@@ -28,5 +28,6 @@ type WechyClaims struct {
UserID int `json:"user/id"`
UserName string `json:"user/name"`
UserEmail string `json:"user/email"`
+ TenantID int `json:"tenant/id"`
jwt.StandardClaims
}
diff --git a/migrations/201703310857_add_tenant_to_users.up.sql b/migrations/201703310857_add_tenant_to_users.up.sql
new file mode 100644
index 000000000..75febb1f9
--- /dev/null
+++ b/migrations/201703310857_add_tenant_to_users.up.sql
@@ -0,0 +1,10 @@
+ALTER TABLE users ADD tenant_id INT REFERENCES tenants(id);
+
+UPDATE users
+SET tenant_id = ideas.tenant_id
+FROM ideas
+WHERE ideas.user_id = users.id;
+
+UPDATE users
+SET tenant_id = (SELECT id FROM tenants LIMIT 1)
+WHERE tenant_id IS NULL
\ No newline at end of file