Skip to content

Commit c249e3f

Browse files
committed
Support for People commands
1 parent fa3bfc1 commit c249e3f

37 files changed

+821
-32
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $(DARWIN):
2727
env GOOS=darwin GOARCH=arm64 go build -v -o $(DARWIN) -ldflags="-s -w -X main.version=$(VERSION)" ./alfresco.go
2828

2929
test:
30-
cd test && ./test_node.sh
30+
cd test && ./test_node.sh && ./test_people.sh
3131

3232
docs:
3333
cd docs/generate && go build generate.go && ./generate

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ Detailed documentation is available in [docs/alfresco.md](docs/alfresco.md)
178178
## TODO
179179

180180
* Site commands
181-
* Person commands
182181
* Group commands
183182
* Search commands
184183
* Provide pre-built programs for Windows, Linux, Mac AMD64 & Mac ARM64

alfresco.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/aborroy/alfresco-cli/cmd"
88
_ "github.com/aborroy/alfresco-cli/cmd/config"
99
_ "github.com/aborroy/alfresco-cli/cmd/node"
10+
_ "github.com/aborroy/alfresco-cli/cmd/people"
1011
)
1112

1213
func main() {

cmd/node/get.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func GetNodeProperties(
2727
Method: http.MethodGet,
2828
Format: httpclient.None,
2929
Url: nodeUrlPath + nodeId,
30-
Parameters: GetUrlParams(params),
30+
Parameters: httpclient.GetUrlParams(params),
3131
ResponseBodyOutput: responseBody,
3232
}
3333

cmd/node/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ListNode(
3333
Method: http.MethodGet,
3434
Format: httpclient.None,
3535
Url: nodeUrlPath + nodeId + "/children",
36-
Parameters: GetUrlParams(params),
36+
Parameters: httpclient.GetUrlParams(params),
3737
ResponseBodyOutput: responseBody,
3838
}
3939

cmd/node/node.go

-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,11 @@ package node
33
import (
44
"bytes"
55
"encoding/json"
6-
"net/url"
76

87
"github.com/aborroy/alfresco-cli/cmd"
98
"github.com/spf13/cobra"
109
)
1110

12-
func GetUrlParams(params map[string]string) url.Values {
13-
var parameters = url.Values{}
14-
for key, value := range params {
15-
parameters.Add(key, value)
16-
}
17-
return parameters
18-
}
19-
2011
func GetNodeId(rootNodeId string, relativePath string) string {
2112
var responseBodyNodeId bytes.Buffer
2213
GetNodeProperties(rootNodeId, relativePath, &responseBodyNodeId)

cmd/people/create.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package people
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"net/http"
7+
"strings"
8+
9+
"github.com/aborroy/alfresco-cli/cmd"
10+
"github.com/aborroy/alfresco-cli/httpclient"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
const CreatePeopleCmdId string = "[PEOPLE CREATE]"
15+
16+
var password string
17+
var firstName string
18+
var lastName string
19+
var email string
20+
var properties []string
21+
var peopleCreateCmd = &cobra.Command{
22+
Use: "create",
23+
Short: "Create new Person in ACS Repository",
24+
Long: `Creates a new person in the repository.
25+
The person can be created setting only required properties.`,
26+
Run: func(command *cobra.Command, args []string) {
27+
28+
var personCreate PersonUpdate
29+
personCreate.ID = personId
30+
personCreate.Password = password
31+
personCreate.FirstName = firstName
32+
personCreate.LastName = lastName
33+
personCreate.Email = email
34+
personCreate.Enabled = true
35+
PopulatePersonUpdate(properties, &personCreate)
36+
jsonPersonCreate, _ := json.Marshal(personCreate)
37+
38+
execution := &httpclient.HttpExecution{
39+
Method: http.MethodPost,
40+
Data: string(jsonPersonCreate),
41+
Format: httpclient.Json,
42+
Url: strings.TrimSuffix(peopleUrlPath, "/"),
43+
ResponseBodyOutput: &responseBody,
44+
}
45+
46+
_error := httpclient.Execute(execution)
47+
if _error != nil {
48+
cmd.ExitWithError(CreatePeopleCmdId, _error)
49+
}
50+
},
51+
PostRun: func(command *cobra.Command, args []string) {
52+
log.Println(CreatePeopleCmdId, "Person "+personId+" has been created")
53+
},
54+
}
55+
56+
func init() {
57+
peopleCmd.AddCommand(peopleCreateCmd)
58+
peopleCreateCmd.Flags().StringVarP(&personId, "personId", "i", "", "Username of the user in Alfresco Repository.")
59+
peopleCreateCmd.Flags().StringVarP(&password, "password", "s", "", "Password of the user in Alfresco Repository.")
60+
peopleCreateCmd.Flags().StringVarP(&firstName, "firstName", "f", "", "First Name of the user in Alfresco Repository.")
61+
peopleCreateCmd.Flags().StringVarP(&lastName, "lastName", "l", "", "Last Name of the user in Alfresco Repository.")
62+
peopleCreateCmd.Flags().StringVarP(&email, "email", "e", "", "Email of the user in Alfresco Repository.")
63+
peopleCreateCmd.Flags().StringArrayVarP(&properties, "properties", "p", nil,
64+
"Property=Value list containing properties to be created. Property strings accepted: "+
65+
"description, skypeID, googleID, instantMessageID, jobTitle, location, mobile, telephone, "+
66+
"company.organization, company.address1, company.address2, company.address3, company.postcode, "+
67+
"company.telephone, company.fax, company.email")
68+
peopleCreateCmd.Flags().SortFlags = false
69+
peopleCreateCmd.MarkFlagRequired("personId")
70+
peopleCreateCmd.MarkFlagRequired("password")
71+
peopleCreateCmd.MarkFlagRequired("firstName")
72+
peopleCreateCmd.MarkFlagRequired("lastName")
73+
peopleCreateCmd.MarkFlagRequired("email")
74+
75+
}

cmd/people/delete.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package people
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/aborroy/alfresco-cli/cmd"
8+
"github.com/aborroy/alfresco-cli/httpclient"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
const DeletePeopleCmdId string = "[NODE DELETE]"
13+
const peopleDeleteUrlPath string = "/s/api/people/"
14+
15+
var peopleDeleteCmd = &cobra.Command{
16+
Use: "delete",
17+
Short: "Delete a Person existing in the repository",
18+
Long: `Removes an existing person from the repository.`,
19+
Run: func(command *cobra.Command, args []string) {
20+
execution := &httpclient.HttpExecution{
21+
Method: http.MethodDelete,
22+
Format: httpclient.None,
23+
Url: peopleDeleteUrlPath + personId,
24+
ResponseBodyOutput: &responseBody,
25+
}
26+
_error := httpclient.Execute(execution)
27+
if _error != nil {
28+
cmd.ExitWithError(DeletePeopleCmdId, _error)
29+
}
30+
},
31+
PostRun: func(command *cobra.Command, args []string) {
32+
log.Println(DeletePeopleCmdId, "Person "+personId+" has been deleted")
33+
},
34+
}
35+
36+
func init() {
37+
peopleCmd.AddCommand(peopleDeleteCmd)
38+
peopleDeleteCmd.Flags().StringVarP(&personId, "personId", "i", "", "Username of the user in Alfresco Repository.")
39+
peopleDeleteCmd.MarkFlagRequired("personId")
40+
}

cmd/people/get.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package people
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/aborroy/alfresco-cli/cmd"
8+
"github.com/aborroy/alfresco-cli/httpclient"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
const GetPeopleCmdId string = "[PEOPLE GET]"
13+
14+
var peopleGetCmd = &cobra.Command{
15+
Use: "get",
16+
Short: "Get Person information from repository",
17+
Long: `Properties of the Person are retrieved.
18+
Properties are provided as output of the command.`,
19+
Run: func(command *cobra.Command, args []string) {
20+
execution := &httpclient.HttpExecution{
21+
Method: http.MethodGet,
22+
Format: httpclient.None,
23+
Url: peopleUrlPath + personId,
24+
ResponseBodyOutput: &responseBody,
25+
}
26+
_error := httpclient.Execute(execution)
27+
if _error != nil {
28+
cmd.ExitWithError(GetPeopleCmdId, _error)
29+
}
30+
},
31+
PostRun: func(command *cobra.Command, args []string) {
32+
log.Println(GetPeopleCmdId, "Details for person "+personId+" have been retrieved")
33+
},
34+
}
35+
36+
func init() {
37+
peopleCmd.AddCommand(peopleGetCmd)
38+
peopleGetCmd.Flags().StringVarP(&personId, "personId", "i", "", "Username of the user in Alfresco Repository. You can use the -me- string in place of <personId> to specify the currently authenticated user.")
39+
peopleGetCmd.MarkFlagRequired("personId")
40+
}

cmd/people/list.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package people
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"strconv"
7+
8+
"github.com/aborroy/alfresco-cli/cmd"
9+
"github.com/aborroy/alfresco-cli/httpclient"
10+
"github.com/aborroy/alfresco-cli/nativestore"
11+
"github.com/spf13/cobra"
12+
"github.com/spf13/viper"
13+
)
14+
15+
const ListPeopleCmdId string = "[PEOPLE LIST]"
16+
17+
var skipCount int
18+
var maxItems int
19+
var peopleListCmd = &cobra.Command{
20+
Use: "list",
21+
Short: "Get Person list from repository",
22+
Long: `Properties List is provided as output of the command.
23+
If list elements count is greater than "maxItems" flag, output includes "HasMoreItems" field set to true.
24+
Incrementing the "skipCount" flag on a loop will allow to retrieve all the children nodes.`,
25+
Run: func(command *cobra.Command, args []string) {
26+
if maxItems == -1 {
27+
maxItems = viper.GetInt(nativestore.MaxItemsLabel)
28+
}
29+
var params = make(map[string]string)
30+
params["skipCount"] = strconv.Itoa(skipCount)
31+
params["maxItems"] = strconv.Itoa(maxItems)
32+
33+
execution := &httpclient.HttpExecution{
34+
Method: http.MethodGet,
35+
Format: httpclient.None,
36+
Url: peopleUrlPath,
37+
Parameters: httpclient.GetUrlParams(params),
38+
ResponseBodyOutput: &responseBody,
39+
}
40+
41+
_error := httpclient.Execute(execution)
42+
if _error != nil {
43+
cmd.ExitWithError(ListPeopleCmdId, _error)
44+
}
45+
},
46+
PostRun: func(command *cobra.Command, args []string) {
47+
log.Println(ListPeopleCmdId, "Person list has been retrieved")
48+
},
49+
}
50+
51+
func init() {
52+
peopleCmd.AddCommand(peopleListCmd)
53+
peopleListCmd.Flags().IntVar(&skipCount, "skipCount", 0, "Skip a number of initial nodes from the list")
54+
peopleListCmd.Flags().IntVar(&maxItems, "maxItems", -1, "Maximum number of nodes in the response list (max. 1000)")
55+
peopleListCmd.Flags().SortFlags = false
56+
}

0 commit comments

Comments
 (0)