mirror of
https://github.com/paralus/paralus.git
synced 2026-08-24 15:47:19 +00:00
Merge sentry view table models
This commit is contained in:
@@ -30,7 +30,7 @@ func GetProjectOrganization(ctx context.Context, db bun.IDB, id uuid.UUID) (stri
|
||||
|
||||
func GetFileteredProjects(ctx context.Context, db bun.IDB, account, partner, org uuid.UUID) ([]models.Project, error) {
|
||||
ids := []uuid.UUID{}
|
||||
sp := []models.SentryAccountPermission{}
|
||||
sp := []models.AccountPermission{}
|
||||
err := db.NewSelect().Model(&sp).
|
||||
ColumnExpr("distinct account_id, project_id").
|
||||
Where("sentry_account_permission.partner_id = ?", partner).
|
||||
|
||||
@@ -73,7 +73,7 @@ type userProjectnamesaceRole struct {
|
||||
|
||||
// TODO: find a better name for the function
|
||||
func GetQueryFilteredUsers(ctx context.Context, db bun.IDB, partner, org, group, role uuid.UUID, projects []uuid.UUID) ([]uuid.UUID, error) {
|
||||
p := []models.SentryAccountPermission{}
|
||||
p := []models.AccountPermission{}
|
||||
q := db.NewSelect().Model(&p).ColumnExpr("DISTINCT account_id")
|
||||
|
||||
q.Where("partner_id = ?", partner).
|
||||
|
||||
@@ -11,13 +11,15 @@ type AccountPermission struct {
|
||||
bun.BaseModel `bun:"table:sentry_account_permission,alias:sap"`
|
||||
|
||||
AccountId uuid.UUID `bun:"account_id,type:uuid"`
|
||||
ProjecttId uuid.UUID `bun:"project_id"`
|
||||
ProjectId uuid.UUID `bun:"project_id,type:uuid"`
|
||||
GroupId uuid.UUID `bun:"group_id,type:uuid"`
|
||||
RoleId uuid.UUID `bun:"role_id,type:uuid"`
|
||||
RoleName string `bun:"role_name,type:string"`
|
||||
OrganizationId uuid.UUID `bun:"organization_id,type:uuid"`
|
||||
PartnerId uuid.UUID `bun:"partner_id,type:uuid"`
|
||||
RoleName string `bun:"role_name"`
|
||||
IsGlobal bool `bun:"is_global"`
|
||||
Scope string `bun:"scope"`
|
||||
PermissionName string `bun:"permission_name"`
|
||||
BaseUrl string `bun:"base_url"`
|
||||
IsGlobal bool `bun:"is_global,notnull,default:true"` // does not matter
|
||||
Scope string `bun:"scope,notnull"`
|
||||
PermissionName string `bun:"permission_name,type:string"`
|
||||
BaseUrl string `bun:"base_url,type:string"`
|
||||
Urls json.RawMessage `bun:"urls,type:jsonb"`
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type SentryAccountPermission struct {
|
||||
bun.BaseModel `bun:"table:sentry_account_permission,alias:sentry_account_permission"`
|
||||
|
||||
AccountId uuid.UUID `bun:"account_id,type:uuid"`
|
||||
ProjectId uuid.UUID `bun:"project_id,type:uuid"`
|
||||
GroupId uuid.UUID `bun:"group_id,type:uuid"`
|
||||
RoleId uuid.UUID `bun:"role_id,type:uuid"`
|
||||
OrganizationId uuid.UUID `bun:"organization_id,type:uuid"`
|
||||
PartnerId uuid.UUID `bun:"partner_id,type:uuid"`
|
||||
IsGlobal bool `bun:"is_global,notnull,default:true"` // does not matter
|
||||
Scope string `bun:"scope,notnull"`
|
||||
Permission string `bun:"permission_name,type:string"`
|
||||
BaseUrl string `bun:"base_url,type:string"`
|
||||
Urls json.RawMessage `bun:"urls,type:jsonb"`
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func prepareAccountPermissionResponse(aps models.AccountPermission) sentry.Accou
|
||||
}
|
||||
return sentry.AccountPermission{
|
||||
AccountID: aps.AccountId.String(),
|
||||
ProjectID: aps.ProjecttId.String(),
|
||||
ProjectID: aps.ProjectId.String(),
|
||||
OrganizationID: aps.OrganizationId.String(),
|
||||
PartnerID: aps.PartnerId.String(),
|
||||
RoleName: aps.RoleName,
|
||||
|
||||
+1
-2
@@ -427,7 +427,6 @@ func (s *userService) GetUserInfo(ctx context.Context, user *userv3.User) (*user
|
||||
}
|
||||
permissions = append(
|
||||
permissions,
|
||||
// TODO: rename permissions to permission
|
||||
&userv3.Permission{
|
||||
Project: p.Project,
|
||||
Namespace: p.Namespace,
|
||||
@@ -661,7 +660,7 @@ func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiK
|
||||
}
|
||||
// fetch the metadata information required to populate cli config
|
||||
var proj models.Project
|
||||
_, err = dao.GetByID(ctx, s.db, ap.ProjecttId, &proj)
|
||||
_, err = dao.GetByID(ctx, s.db, ap.ProjectId, &proj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ func TestUserList(t *testing.T) {
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(puuid))
|
||||
mock.ExpectQuery(`SELECT "organization"."id" FROM "authsrv_organization" AS "organization"`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(ouuid))
|
||||
mock.ExpectQuery(`SELECT DISTINCT account_id FROM "sentry_account_permission" WHERE .partner_id = '` + puuid + `'. AND .organization_id = '` + ouuid + `'`).
|
||||
mock.ExpectQuery(`SELECT DISTINCT account_id FROM "sentry_account_permission" AS "sap" WHERE .partner_id = '` + puuid + `'. AND .organization_id = '` + ouuid + `'`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"account_id"}).AddRow(uuuid1).AddRow(uuuid2))
|
||||
mock.ExpectQuery(`SELECT "identities"."id", .*WHERE .id IN .'` + uuuid1 + `', '` + uuuid2 + `'.. LIMIT 10`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "traits"}).
|
||||
@@ -442,7 +442,7 @@ func TestUserList(t *testing.T) {
|
||||
t.Fatal("could not list users:", err)
|
||||
}
|
||||
if userlist.Metadata.Count != 2 {
|
||||
t.Errorf("incorrect number of users returned, expected 2; got %v", userlist.Metadata.Count)
|
||||
t.Fatalf("incorrect number of users returned, expected 2; got %v", userlist.Metadata.Count)
|
||||
}
|
||||
if userlist.Items[0].Metadata.Name != "johndoe@provider.com" || userlist.Items[1].Metadata.Name != "johndoe@provider.com" {
|
||||
t.Errorf("incorrect user names returned when listing; expected '%v' and '%v'; got '%v' and '%v'", "johndoe@provider.com", "johndoe@provider.com", userlist.Items[0].Metadata.Name, userlist.Items[1].Metadata.Name)
|
||||
@@ -480,7 +480,7 @@ func TestUserFiletered(t *testing.T) {
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(puuid))
|
||||
mock.ExpectQuery(`SELECT "organization"."id" FROM "authsrv_organization" AS "organization"`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(ouuid))
|
||||
mock.ExpectQuery(`SELECT DISTINCT account_id FROM "sentry_account_permission" WHERE .partner_id = '` + puuid + `'. AND .organization_id = '` + ouuid + `'`).
|
||||
mock.ExpectQuery(`SELECT DISTINCT account_id FROM "sentry_account_permission" AS "sap" WHERE .partner_id = '` + puuid + `'. AND .organization_id = '` + ouuid + `'`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"account_id"}).AddRow(uuuid1).AddRow(uuuid2))
|
||||
mock.ExpectQuery(`SELECT "identities"."id", .*WHERE .id IN .'` + uuuid1 + `', '` + uuuid2 + `'.. AND .traits ->> 'email' ILIKE '%filter-query%'. OR .traits ->> 'first_name' ILIKE '%filter-query%'. OR .traits ->> 'last_name' ILIKE '%filter-query%'. ORDER BY "traits ->> 'email' asc" LIMIT 50 OFFSET 20`).
|
||||
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "traits"}).
|
||||
@@ -513,7 +513,7 @@ func TestUserFiletered(t *testing.T) {
|
||||
t.Fatal("could not list users:", err)
|
||||
}
|
||||
if userlist.Metadata.Count != 2 {
|
||||
t.Errorf("incorrect number of users returned, expected 2; got %v", userlist.Metadata.Count)
|
||||
t.Fatalf("incorrect number of users returned, expected 2; got %v", userlist.Metadata.Count)
|
||||
}
|
||||
|
||||
if userlist.Items[0].Metadata.Name != "johndoe@provider.com" {
|
||||
|
||||
Reference in New Issue
Block a user