Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/getfider/fider into ui-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwoberts committed Sep 29, 2024
2 parents 4aecc0e + 55dfbc9 commit 9d56941
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 87 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64/v8]
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Dump GitHub context
Expand Down Expand Up @@ -40,7 +43,7 @@ jobs:
push: true
context: .
build-args: COMMITHASH=${{ github.event.workflow_run.head_sha }}
platforms: linux/amd64,linux/arm64/v8
platforms: ${{ matrix.platform }}
tags: getfider/fider:PR_${{ github.event.workflow_run.pull_requests[0].number }}
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -52,7 +55,7 @@ jobs:
push: true
context: .
build-args: COMMITHASH=${{ github.event.workflow_run.head_sha }}
platforms: linux/amd64,linux/arm64/v8
platforms: ${{ matrix.platform }}
tags: |
getfider/fider:SHA_${{ github.event.workflow_run.head_sha }}
getfider/fider:${{ github.event.workflow_run.head_branch == 'main' && 'main' || 'stable' }}
Expand All @@ -66,7 +69,7 @@ jobs:
push: true
context: .
build-args: COMMITHASH=${{ github.event.workflow_run.head_sha }}
platforms: linux/amd64,linux/arm64/v8
platforms: ${{ matrix.platform }}
tags: getfider/fider:${{ github.event.workflow_run.display_title }}
cache-from: type=gha
cache-to: type=gha,mode=max
29 changes: 15 additions & 14 deletions app/cmd/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func routes(r *web.Engine) *web.Engine {
})

r.Use(middlewares.Secure())
r.Use(middlewares.CSRF())
r.Use(middlewares.Compress())

assets := r.Group()
Expand All @@ -56,13 +55,6 @@ func routes(r *web.Engine) *web.Engine {
r.Use(middlewares.User())

r.Get("/privacy", handlers.LegalPage("Privacy Policy", "privacy.md"))
r.Get("/terms", handlers.LegalPage("Terms of Service", "terms.md"))

r.Post("/_api/tenants", handlers.CreateTenant())
r.Get("/_api/tenants/:subdomain/availability", handlers.CheckAvailability())
r.Get("/signup", handlers.SignUp())
r.Get("/oauth/:provider", handlers.SignInByOAuth())
r.Get("/oauth/:provider/callback", handlers.OAuthCallback())

if env.IsBillingEnabled() {
wh := r.Group()
Expand All @@ -71,7 +63,17 @@ func routes(r *web.Engine) *web.Engine {
}
}

// Starting from this step, a Tenant is required
r.Use(middlewares.CSRF())

r.Get("/terms", handlers.LegalPage("Terms of Service", "terms.md"))

r.Post("/_api/tenants", handlers.CreateTenant())
r.Get("/_api/tenants/:subdomain/availability", handlers.CheckAvailability())
r.Get("/signup", handlers.SignUp())
r.Get("/oauth/:provider", handlers.SignInByOAuth())
r.Get("/oauth/:provider/callback", handlers.OAuthCallback())

//Starting from this step, a Tenant is required
r.Use(middlewares.RequireTenant())

r.Get("/sitemap.xml", handlers.Sitemap())
Expand All @@ -96,7 +98,7 @@ func routes(r *web.Engine) *web.Engine {
r.Get("/oauth/:provider/token", handlers.OAuthToken())
r.Get("/oauth/:provider/echo", handlers.OAuthEcho())

// If tenant is pending, block it from using any other route
//If tenant is pending, block it from using any other route
r.Use(middlewares.BlockPendingTenants())

r.Get("/signin", handlers.SignInPage())
Expand All @@ -106,7 +108,7 @@ func routes(r *web.Engine) *web.Engine {
r.Post("/_api/signin/complete", handlers.CompleteSignInProfile())
r.Post("/_api/signin", handlers.SignInByEmail())

// Block if it's private tenant with unauthenticated user
//Block if it's private tenant with unauthenticated user
r.Use(middlewares.CheckTenantPrivacy())

r.Get("/", handlers.Index())
Expand All @@ -115,7 +117,7 @@ func routes(r *web.Engine) *web.Engine {

ui := r.Group()
{
// From this step, a User is required
//From this step, a User is required
ui.Use(middlewares.IsAuthenticated())

ui.Get("/settings", handlers.UserSettings())
Expand All @@ -129,7 +131,6 @@ func routes(r *web.Engine) *web.Engine {
ui.Post("/_api/user/change-email", handlers.ChangeUserEmail())
ui.Post("/_api/notifications/read-all", handlers.ReadAllNotifications())
ui.Get("/_api/notifications/unread/total", handlers.TotalUnreadNotifications())
ui.Get("/_api/notifications/unread", handlers.GetAllNotifications())

// From this step, only Collaborators and Administrators are allowed
ui.Use(middlewares.IsAuthorized(enum.RoleCollaborator, enum.RoleAdministrator))
Expand All @@ -147,7 +148,7 @@ func routes(r *web.Engine) *web.Engine {
ui.Get("/admin/authentication", handlers.ManageAuthentication())
ui.Get("/_api/admin/oauth/:provider", handlers.GetOAuthConfig())

// From this step, only Administrators are allowed
//From this step, only Administrators are allowed
ui.Use(middlewares.IsAuthorized(enum.RoleAdministrator))

ui.Get("/admin/export", handlers.Page("Export · Site Settings", "", "Administration/pages/Export.page"))
Expand Down
2 changes: 0 additions & 2 deletions app/handlers/webhooks/paddle.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func handlePaddleSubscriptionCreated(c *web.Context, params url.Values) error {
c.Enqueue(tasks.UserListUpdateCompany(&dto.UserListUpdateCompany{
TenantID: passthrough.TenantID,
BillingStatus: enum.BillingActive,
Name: c.Tenant().Name,
}))
}

Expand Down Expand Up @@ -107,7 +106,6 @@ func handlePaddleSubscriptionCancelled(c *web.Context, params url.Values) error
c.Enqueue(tasks.UserListUpdateCompany(&dto.UserListUpdateCompany{
TenantID: passthrough.TenantID,
BillingStatus: enum.BillingCancelled,
Name: c.Tenant().Name,
}))
}

Expand Down
52 changes: 12 additions & 40 deletions app/pkg/dbx/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"database/sql"
stdErrors "errors"
"github.com/lib/pq"
"os"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -65,23 +63,20 @@ func Migrate(ctx context.Context, path string) error {

totalMigrationsExecuted := 0

pendingVersions, err := getPendingMigrations(versions)
if err != nil {
return errors.Wrap(err, "failed to get pending migrations")
}

// Apply all migrations
for _, version := range pendingVersions {
fileName := versionFiles[version]
log.Infof(ctx, "Running Version: @{Version} (@{FileName})", dto.Props{
"Version": version,
"FileName": fileName,
})
err := runMigration(ctx, version, path, fileName)
if err != nil {
return errors.Wrap(err, "failed to run migration '%s'", fileName)
for _, version := range versions {
if version > lastVersion {
fileName := versionFiles[version]
log.Infof(ctx, "Running Version: @{Version} (@{FileName})", dto.Props{
"Version": version,
"FileName": fileName,
})
err := runMigration(ctx, version, path, fileName)
if err != nil {
return errors.Wrap(err, "failed to run migration '%s'", fileName)
}
totalMigrationsExecuted++
}
totalMigrationsExecuted++
}

if totalMigrationsExecuted > 0 {
Expand Down Expand Up @@ -145,26 +140,3 @@ func getLastMigration() (int, error) {

return int(lastVersion.Int64), nil
}

func getPendingMigrations(versions []int) ([]int, error) {
pendingMigrations := append([]int(nil), versions...)

rows, err := conn.Query("SELECT version FROM migrations_history WHERE version = ANY($1)", pq.Array(pendingMigrations))
if err != nil {
return nil, err
}
defer rows.Close()

for rows.Next() {
var version int
if err := rows.Scan(&version); err != nil {
return nil, errors.Wrap(err, "failed to scan version")
}
i := slices.Index(pendingMigrations, version)
if i != -1 {
pendingMigrations = slices.Delete(pendingMigrations, i, i+1)
}
}

return pendingMigrations, nil
}
24 changes: 0 additions & 24 deletions app/pkg/dbx/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,6 @@ func TestMigrate_Success(t *testing.T) {
trx.MustRollback()
}

func TestMigrate_SuccessWithPastMigration(t *testing.T) {
setupMigrationTest(t)
ctx := context.Background()

err := dbx.Migrate(ctx, "/app/pkg/dbx/testdata/migration_success")
Expect(err).IsNil()

err = dbx.Migrate(ctx, "/app/pkg/dbx/testdata/migration_success_with_new_migrations")
Expect(err).IsNil()

trx, _ := dbx.BeginTx(ctx)
var version string
err = trx.Scalar(&version, "SELECT version FROM migrations_history WHERE version = '209901010000' LIMIT 1")
Expect(err).IsNil()
Expect(version).Equals("209901010000")

var count int
err = trx.Scalar(&count, "SELECT COUNT(*) FROM migrations_history WHERE version IN (209901010000,210001010002)")
Expect(err).IsNil()
Expect(count).Equals(2)

trx.MustRollback()
}

func TestMigrate_Failure(t *testing.T) {
setupMigrationTest(t)
ctx := context.Background()
Expand Down

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion app/services/userlist/userlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ func updateUserListCompany(ctx context.Context, c *cmd.UserListUpdateCompany) er
Identifier: strconv.Itoa(c.TenantId),
Name: c.Name,
}

if c.BillingStatus > 0 {
company.Properties = map[string]interface{}{
"billing_status": c.BillingStatus,
"billing_status": c.BillingStatus.String(),
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/services/userlist/userlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func reset() {
bus.Init(userlist.Service{}, httpclientmock.Service{}, userlist_mock.Service{})
}

func TestCreatTenant_Success(t *testing.T) {
func TestCreateTenant_Success(t *testing.T) {
RegisterT(t)
env.Config.HostMode = "multi"
reset()
Expand Down Expand Up @@ -94,6 +94,9 @@ func TestUpdateTenant_BillingStatusUpdatedIfSet(t *testing.T) {
containsBillingStatus := strings.Contains(string(body), "billing_status")
Expect(containsBillingStatus).IsTrue()

// Also check we're using the enum string, not the int value
Expect(strings.Contains(string(body), "billing_status\":\"active\"")).IsTrue()

}

func TestUpdateTenant_BillingStatusNotUpdatedIfNotSet(t *testing.T) {
Expand Down

0 comments on commit 9d56941

Please sign in to comment.