-
Notifications
You must be signed in to change notification settings - Fork 0
Provisioning for page #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
4ca8fd3
3c26315
59cc4de
ab582c1
6a265ec
df7afda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,13 +102,60 @@ func (c *Client) GetGroupPage(ctx context.Context, groupID int64, pageID int64) | |
| return &ret, nil | ||
| } | ||
|
|
||
| func (c *Client) InsertGroupPage(ctx context.Context, groupID int64, pageID int64, accessLevel string) error { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("inserting group page", zap.Int64("group_id", groupID), zap.Int64("page_id", pageID), zap.String("access_level", accessLevel)) | ||
|
|
||
| args := []interface{}{groupID, pageID, accessLevel} | ||
| sb := &strings.Builder{} | ||
| _, _ = sb.WriteString(`INSERT INTO group_pages ("groupId", "pageId", "accessLevel", "createdAt", "updatedAt") VALUES ($1, $2, $3, NOW(), NOW())`) | ||
|
|
||
| if _, err := c.db.Exec(ctx, sb.String(), args...); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *Client) UpdateGroupPage(ctx context.Context, id int64, accessLevel string) error { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("updating group page", zap.Int64("id", id), zap.String("access_level", accessLevel)) | ||
|
|
||
| args := []interface{}{accessLevel, id} | ||
| sb := &strings.Builder{} | ||
| _, _ = sb.WriteString(`UPDATE group_pages SET "accessLevel" = $1 WHERE "id"=$2`) | ||
|
|
||
| _, err := c.db.Exec(ctx, sb.String(), args...) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *Client) DeleteGroupPage(ctx context.Context, id int64) error { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("deleting group page", zap.Int64("id", id)) | ||
|
|
||
| args := []interface{}{id} | ||
| sb := &strings.Builder{} | ||
| _, _ = sb.WriteString(`DELETE FROM group_pages WHERE "id"=$1`) | ||
|
|
||
| if _, err := c.db.Exec(ctx, sb.String(), args...); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *Client) GetGroupFolderDefault(ctx context.Context, groupID int64, folderID int64) (*GroupFolderDefault, error) { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("getting group folder default", zap.Int64("group_id", groupID), zap.Int64("folder_id", folderID)) | ||
|
|
||
| args := []interface{}{groupID, folderID} | ||
| sb := &strings.Builder{} | ||
| _, _ = sb.WriteString(`select "id", "accessLevel" from group_folder_defaults WHERE "groupId"=$1 AND "folderId"=$2`) | ||
| _, _ = sb.WriteString(``) | ||
|
|
||
| var ret GroupFolderDefault | ||
| err := pgxscan.Get(ctx, c.db, &ret, sb.String(), args...) | ||
|
|
@@ -219,6 +266,38 @@ func (c *Client) GetGroup(ctx context.Context, groupID int64) (*GroupModel, erro | |
| return &ret, nil | ||
| } | ||
|
|
||
| func (c *Client) GetGroupByName(ctx context.Context, organizationID *int64, name string) (*GroupModel, error) { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("getting group by name", zap.Any("organization_id", organizationID), zap.String("name", name)) | ||
|
|
||
| args := []interface{}{organizationID, name} | ||
| sb := &strings.Builder{} | ||
| _, _ = sb.WriteString(`select "id", "name", "organizationId", "universalAccess", "universalResourceAccess", | ||
| "universalQueryLibraryAccess", "userListAccess", "auditLogAccess", "unpublishedReleaseAccess" | ||
| from groups WHERE "organizationId"=$1 AND "name"=$2`) | ||
|
|
||
| var ret GroupModel | ||
| err := pgxscan.Get(ctx, c.db, &ret, sb.String(), args...) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &ret, nil | ||
| } | ||
|
|
||
| func (c *Client) CreateGroup(ctx context.Context, organizationID *int64, name string) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they'll need to update the permissions they give our connectors. I will let CS know |
||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("create group", zap.Any("organization_id", organizationID), zap.String("name", name)) | ||
|
|
||
| args := []interface{}{name, organizationID} | ||
|
|
||
| if _, err := c.db.Exec(ctx, `INSERT INTO groups ("name", "organizationId", "createdAt", "updatedAt", "archivedAt", "usageAnalyticsAccess", "themeAccess", "unpublishedReleaseAccess", "accountDetailsAccess") VALUES ($1, $2,NOW(), NOW(), NULL, false, false, false, false)`, args...); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *Client) ListGroupsForOrg(ctx context.Context, orgID int64, pager *Pager) ([]*GroupModel, string, error) { | ||
| l := ctxzap.Extract(ctx) | ||
| l.Debug("listing groups for org", zap.Int64("org_id", orgID)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,17 @@ package connector | |
| import ( | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" | ||
| "github.com/conductorone/baton-sdk/pkg/pagination" | ||
| ) | ||
|
|
||
| func formatObjectID(resourceTypeID string, id int64) string { | ||
| return fmt.Sprintf("%s:%d", resourceTypeID, id) | ||
| return fmt.Sprintf("%c%d", resourceTypeID[0], id) | ||
|
Comment on lines
-13
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| } | ||
|
|
||
| func parseObjectID(id string) (int64, error) { | ||
| parts := strings.SplitN(id, ":", 2) | ||
| if len(parts) != 2 { | ||
| return 0, fmt.Errorf("invalid object ID %s", id) | ||
| } | ||
|
|
||
| return strconv.ParseInt(parts[1], 10, 64) | ||
| return strconv.ParseInt(id[1:], 10, 64) | ||
| } | ||
|
|
||
| func formatGroupObjectID(id int64) string { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should that remain without a SQL statement tho?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not supposed to be empty, I fix it.