From 7def827d26a3de6b35a4e69df1a57b832a0750de Mon Sep 17 00:00:00 2001 From: Paul Yan Date: Thu, 15 Aug 2024 13:05:27 -0400 Subject: [PATCH] fixed group permission bug --- cmd/cli/command.go | 33 +++++++++++++++ cmd/cli/main.go | 2 +- cmd/cli/testdata/test02.xlsx | Bin 0 -> 21934 bytes pkg/client.go | 76 ++++++++++++++++++++++++++++++----- pkg/folder.go | 10 ++++- pkg/groups.go | 68 +++++++++++++++++++++++++++++++ pkg/request.go | 6 ++- 7 files changed, 183 insertions(+), 12 deletions(-) create mode 100644 cmd/cli/testdata/test02.xlsx create mode 100644 pkg/groups.go diff --git a/cmd/cli/command.go b/cmd/cli/command.go index 175839a..757eec0 100644 --- a/cmd/cli/command.go +++ b/cmd/cli/command.go @@ -34,6 +34,7 @@ var ( Subcommands: []*cli.Command{ GetCustodiansCmd, GetFoldersCmd, + GetGroupsCmd, GetMattersCmd, GetLegalholdsCmd, }, @@ -106,6 +107,13 @@ var ( Flags: DefaultListOptions, } + GetGroupsCmd = &cli.Command{ + Name: "groups", + Category: "get", + Action: execute, + Flags: DefaultListOptions, + } + GetMattersCmd = &cli.Command{ Name: "matters", Category: "get", @@ -185,6 +193,8 @@ func execute(ctx *cli.Context) error { return getMatters(ctx) case "legalholds": return getLegalholds(ctx) + case "groups": + return getGroups(ctx) } case "verify": switch ctx.Command.Name { @@ -312,6 +322,29 @@ func getFolders(ctx *cli.Context) error { return nil } +func getGroups(ctx *cli.Context) error { + var err error + var v any + + client := NewClient(ctx) + + if ctx.Int("id") > 0 { + v, err = client.GetGroup(ctx.Int("id")) + } else { + v, err = client.GetGroups(listOptions(ctx)) + } + + if err != nil { + return err + } + + fmt.Printf("%+v\n", v) + + printer := otlh.NewPrinter().JSON().Build() + printer.Print(v) + return nil +} + func getMatters(ctx *cli.Context) error { var err error var v any diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 74876ef..9889ee8 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -14,7 +14,7 @@ func main() { app := &cli.App{ Name: "otlh", - Version: "0.3.6-beta", + Version: "0.3.7-beta", Usage: "Command Line Interface to access Opentext LegalHold service", Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/cmd/cli/testdata/test02.xlsx b/cmd/cli/testdata/test02.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..56b59a42744dbe5eee729e6c819f2020d8943793 GIT binary patch literal 21934 zcmeIaWmH|uwk?bVNN{&|cM0wu+}&LR1P|`+7Th(sLkR93+%32}1bB<&oSVJbx$k|q zweQbs@2s>5nXFm8M)m4dHL7aNl9dE~g$x7^^cn~VhybYS$J$UlFc1(71P~As&}$G4 zK^toaBWnj8MHgEmdo5aLD@*+BS0Ln>Kp=qU|MU5On1L20Ny$z=_%Be8ffXudb;|J3 z`MB=bO0wd*WDvEbx+Iv%AsObG!)v1F-y1F)ydH1s3WNMVx~UjU1oD=U^g75 z8)Wg$E?@SwfhO@r3+;#ApIkrN1fw&UN6Nh9#) z2Zt4>7r*J_Z}X(xUwy-MS=bGqvj!73H6;JOd3A=0#HJ^7-L&5r)jjk(A@Db_ZItrS5QMcc>jTi?CHT%QVbeTXKesN5U(sP6-q@h{OG8oNlPQr@k<3-3=?r#Tk?_JK%Nhbii-YaE(b;RHw zv}CX2Tjw0r_w}xN&fy2EDY}ETm=lc2Q<-lwJ0nYbI@;%- z|7pel4>#Sv6umS?N)nU-KH%8riD0OebAgg@!jevSN6PR4m?8N=mn}Iex9Q&5$2kYy%@Hv{_>E7h@no}dhvY*;0|Y{>ok;kBScf;EW$}K=B~v)% zR@Uq#Pe|!{wjV9YlNb62QRQwQ?nX_sx2o}W=;{{|aK$8=@mn|nE10sw%-thmuQ}~O zvw3b>Zd+K{q{__(U2XdFh^V6Sg+`*(ZldM{_Rd+dm9z4Q+bcWf_4{8K>FzTY0a1*>Vv6}Ct6Tuc^m-==S2gey?Brt8nXW~k&g7*QEzLmXMI zy8C03QCZsk-U|u@AYd=4z|K*9 z1eA$iY2`U8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+@pZZp zK0>7*z(bf{QYF{ya36|m=wpo}2XE1Ju1_gmgle+5?Dbsw7Kt|a4e^9~C>EeG> z@OKpe<_iE7xMdydI_RWc(MtqRN@8rXia@nuii*E87*v%oTk*&*Kn3TN5LlsO33N-E zf?;wC0cTZ$fy~KS?j8SndvRF_+O2P3V-jMz>J1&}*lO-!TPL63d={)EM~IaqG@)(b zhy*@}LK0@gC=07Bkt~{4+B}bNS@)Uug9l6IM<%5itUj$a;1903F+bX*I#+RU`)Po4 zejsEmbqK5>em{N}9BO$Ur2iEvz{El$-i^OL+~dCd;g4rmxSfOK{GVj-b4K+a8T?TO zdOv00@GOHta)1mVnlVM+59tr8?y3Hg0r#^EE(2E@it(ti$uV|PP?1SR6~vamZtvc- z0Aw&}s3Kvy>I2xjGMn^VHP53xMPw`~CT6V&+H9RZKn+X48c5nR%ttKyR^^;lc3+2k zS!bp5p^-(mfobY32KmM}Zw@UxDG$p@E{H&z%@KsyA4pkC$^Ppqnk!I7pQ~tayZPY5 zW~L<-j={Ju?vC2l04GiS@+^QsXaK{QVWh39#bx z+qHXk>VEd)FU|P-irQZRbopKa{50c_D1To^`YTEWKj2`bm#a!IjrjXa{jbTxh5nNK zU-R~tssBDL`fF-!(Z8hrMaJ_a=_SD5J>tItMSn|(UzrC!N lSbra!|B6*9^=GW#L$$0V7+`xF2nZGMZxt}~H^@BS{V%4|3A_LR literal 0 HcmV?d00001 diff --git a/pkg/client.go b/pkg/client.go index ca4350c..49e4a63 100644 --- a/pkg/client.go +++ b/pkg/client.go @@ -106,11 +106,7 @@ func (b *ClientBuilder) Build() *Client { "Content-Type": "application/json", }) - /* - if log.Logger.GetLevel() == zerolog.TraceLevel { - r.SetDebug(true) - } - */ + // r.SetDebug(true) if b.skipVerify { r.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) @@ -252,6 +248,41 @@ func (c *Client) GetFolders(opts Options) (Folders, error) { return resp.Embedded.Folders, nil } +func (c *Client) GetGroup(id int) (Group, error) { + var v []byte + var err error + + group := Group{} + + req, _ := NewRequest().WithTenant(c.tenant).Group().WithID(id).Build() + if v, err = c.Send(req); err != nil { + return group, err + } + if err = json.Unmarshal(v, &group); err != nil { + return group, err + } + + return group, nil +} + +func (c *Client) GetGroups(opts Options) (Groups, error) { + var err error + + var body []byte + var resp GroupsResponse + + req, _ := NewRequest().WithTenant(c.tenant).Get().Group().Build() + if body, err = c.Send(req, opts); err != nil { + return nil, err + } + + if err = json.Unmarshal(body, &resp); err != nil { + return nil, err + } + + return resp.Embedded.Groups, nil +} + func (c *Client) GetMatter(id int) (Matter, error) { var v []byte var err error @@ -504,6 +535,7 @@ func (c *Client) FindFolderByName(name string) (Folder, error) { * * Parameters: * - name: the name of the folder to create + * - groupIDs: list of group ids to associate with the folder * * Returns: * - Folder: the newly created folder @@ -513,13 +545,13 @@ func (c *Client) FindFolderByName(name string) (Folder, error) { * creation is successful, the new folder is returned. If an error occurs, the error * is returned. */ -func (c *Client) CreateFolder(name string) (Folder, error) { +func (c *Client) CreateFolder(name string, groupIDs []int) (Folder, error) { var err error var respBody []byte var folder Folder = Folder{} - var createFolder *CreateFolderBody = NewCreateFolderBody().WithName(name) + var createFolder *CreateFolderBody = NewCreateFolderBody().WithName(name).WithGroupIDs(groupIDs) req, _ := NewRequest().WithTenant(c.tenant).Post().Folder().Build() @@ -537,7 +569,6 @@ func (c *Client) CreateFolder(name string) (Folder, error) { log.Debug().Msgf("created folder %s with id %d", name, folder.ID) return folder, nil - } /** @@ -554,7 +585,13 @@ func (c *Client) FindOrCreateFolder(name string) (Folder, error) { log.Debug().Msgf("folder [%s] not found, creating", name) - return c.CreateFolder(name) + group, err := c.FindGroupByName("All Admins") + if err != nil { + log.Debug().Msg("failed to find defalt admin group [All Admins]") + return Folder{}, err + } + + return c.CreateFolder(name, []int{group.ID}) } /** @@ -669,3 +706,24 @@ func (c *Client) FindLegalhold(name string, matterID int) (Legalhold, error) { return Legalhold{}, fmt.Errorf("legalhold [%s] not found", name) } + +func (c *Client) FindGroupByName(name string) (Group, error) { + var err error + var groups Groups = Groups{} + + log.Debug().Msgf("searching groups by name [%s]", name) + + opts := NewListOptions().WithFilterName(name) + + if groups, err = c.GetGroups(opts); err != nil { + return Group{}, err + } + + for _, group := range groups { + if group.Name == name { + return group, nil + } + } + + return Group{}, fmt.Errorf("group [%s] not found", name) +} diff --git a/pkg/folder.go b/pkg/folder.go index c4bec5e..b4333bb 100644 --- a/pkg/folder.go +++ b/pkg/folder.go @@ -109,10 +109,14 @@ type CreateFolderBody struct { ContactEmail string `json:"contact_email,omitempty"` ContactPhone string `json:"contact_phone,omitempty"` Notes string `json:"notes,omitempty"` + GroupIDs []int `json:"group_ids,omitempty"` } +// TODO: enable group name support func NewCreateFolderBody() *CreateFolderBody { - return &CreateFolderBody{InheritEmailConfig: true} + return &CreateFolderBody{ + InheritEmailConfig: true, + } } func (b *CreateFolderBody) WithName(name string) *CreateFolderBody { @@ -120,3 +124,7 @@ func (b *CreateFolderBody) WithName(name string) *CreateFolderBody { return b } +func (b *CreateFolderBody) WithGroupIDs(groupIDs []int) *CreateFolderBody { + b.GroupIDs = groupIDs + return b +} diff --git a/pkg/groups.go b/pkg/groups.go new file mode 100644 index 0000000..9a00178 --- /dev/null +++ b/pkg/groups.go @@ -0,0 +1,68 @@ +package otlh + +import "fmt" + +type Group struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + Links struct { + Self struct { + Href string `json:"href,omitempty"` + } `json:"self,omitempty"` + Users struct { + Href string `json:"href,omitempty"` + } `json:"users,omitempty"` + Folders struct { + Href string `json:"href,omitempty"` + } `json:"folders,omitempty"` + Site struct { + Href string `json:"href,omitempty"` + } `json:"site,omitempty"` + } `json:"_links,omitempty"` +} + +type Groups []Group + +type GroupsResponse struct { + Links struct { + Self struct { + Href string `json:"href"` + } `json:"self"` + } `json:"_links"` + Page struct { + HasMore bool `json:"has-more"` + TotalCount int `json:"total-count"` + } `json:"page"` + Embedded struct { + Groups []Group `json:"groups"` + } `json:"_embedded"` +} + +type GroupRequest struct { + id int + Request +} + +type GroupRequestBuilder struct { + *GroupRequest +} + +func (b *GroupRequestBuilder) WithID(id int) *GroupRequestBuilder { + b.id = id + return b +} + +func (b *GroupRequestBuilder) Build() (*GroupRequest, error) { + return b.GroupRequest, nil +} + +func (req *GroupRequest) Endpoint() string { + if req.id == 0 { + return fmt.Sprintf("/t/%s/api/%s/groups", req.tenant, APIVERSION) + } + return fmt.Sprintf("/t/%s/api/%s/group/%d", req.tenant, APIVERSION, req.id) +} diff --git a/pkg/request.go b/pkg/request.go index a2a74f0..e56e3f1 100644 --- a/pkg/request.go +++ b/pkg/request.go @@ -53,6 +53,10 @@ func (req *Request) Folder() *FolderRequestBuilder { return &FolderRequestBuilder{FolderRequest: &FolderRequest{Request: *req}} } +func (req *Request) Group() *GroupRequestBuilder { + return &GroupRequestBuilder{GroupRequest: &GroupRequest{Request: *req}} +} + func (req *Request) Matter() *MatterRequestBuilder { return &MatterRequestBuilder{MatterRequest: &MatterRequest{Request: *req}} -} \ No newline at end of file +}