@@ -4,83 +4,53 @@ import (
44 "fmt"
55
66 "github.com/drycc/controller-sdk-go/perms"
7- "github.com/drycc/workflow-cli/pkg/git"
87 "github.com/drycc/workflow-cli/settings"
98)
109
11- // PermsList prints which users have permissions.
12- func (d * DryccCmd ) PermsList (appID string , admin bool , results int ) error {
13- s , appID , err := permsLoad (d .ConfigFile , appID , admin )
14-
10+ // PermCodes prints all perm codenames.
11+ func (d * DryccCmd ) PermCodes (results int ) error {
12+ s , err := settings .Load (d .ConfigFile )
1513 if err != nil {
1614 return err
1715 }
18-
19- var users []string
20-
21- if admin {
22- if results == defaultLimit {
23- results = s .Limit
24- }
25- users , _ , err = perms .ListAdmins (s .Client , results )
26- } else {
27- users , err = perms .List (s .Client , appID )
28- }
29-
16+ codenames , _ , err := perms .Codes (s .Client , results )
3017 if d .checkAPICompatibility (s .Client , err ) != nil {
3118 return err
3219 }
33-
34- table := d .getDefaultFormatTable ([]string {"USERNAME" , "ADMIN" })
35- for _ , user := range users {
36- table .Append ([]string {user , fmt .Sprintf ("%v" , admin )})
20+ table := d .getDefaultFormatTable ([]string {"CODENAME" , "DESCRIPTION" })
21+ for _ , code := range codenames {
22+ table .Append ([]string {code .Codename , code .Description })
3723 }
3824 table .Render ()
3925 return nil
4026}
4127
42- // PermCreate adds a user to an app or makes them an administrator.
43- func (d * DryccCmd ) PermCreate (appID string , username string , admin bool ) error {
44-
45- s , appID , err := permsLoad (d .ConfigFile , appID , admin )
46-
28+ // PermList prints which users have permissions.
29+ func (d * DryccCmd ) PermList (codename string , results int ) error {
30+ s , err := settings .Load (d .ConfigFile )
4731 if err != nil {
4832 return err
4933 }
50-
51- if admin {
52- d .Printf ("Adding %s to system administrators... " , username )
53- err = perms .NewAdmin (s .Client , username )
54- } else {
55- d .Printf ("Adding %s to %s collaborators... " , username , appID )
56- err = perms .New (s .Client , appID , username )
57- }
58-
34+ perms , _ , err := perms .List (s .Client , codename , results )
5935 if d .checkAPICompatibility (s .Client , err ) != nil {
6036 return err
6137 }
62-
63- d .Println ("done" )
64-
38+ table := d .getDefaultFormatTable ([]string {"ID" , "CODENAME" , "UNIQUEID" , "USERNAME" })
39+ for _ , perm := range perms {
40+ table .Append ([]string {fmt .Sprintf ("%d" , perm .ID ), perm .Codename , perm .Uniqueid , perm .Username })
41+ }
42+ table .Render ()
6543 return nil
6644}
6745
68- // PermDelete removes a user from an app or revokes admin privileges.
69- func (d * DryccCmd ) PermDelete (appID , username string , admin bool ) error {
70-
71- s , appID , err := permsLoad (d .ConfigFile , appID , admin )
72-
46+ // PermCreate create user perm to user.
47+ func (d * DryccCmd ) PermCreate (codename , uniqueid , username string ) error {
48+ s , err := settings .Load (d .ConfigFile )
7349 if err != nil {
7450 return err
7551 }
76-
77- if admin {
78- d .Printf ("Removing %s from system administrators... " , username )
79- err = perms .DeleteAdmin (s .Client , username )
80- } else {
81- d .Printf ("Removing %s from %s collaborators... " , username , appID )
82- err = perms .Delete (s .Client , appID , username )
83- }
52+ d .Printf ("Adding %s to %s:%s collaborators... " , username , codename , uniqueid )
53+ err = perms .Create (s .Client , codename , uniqueid , username )
8454
8555 if d .checkAPICompatibility (s .Client , err ) != nil {
8656 return err
@@ -91,20 +61,18 @@ func (d *DryccCmd) PermDelete(appID, username string, admin bool) error {
9161 return nil
9262}
9363
94- func permsLoad ( cf , appID string , admin bool ) ( * settings. Settings , string , error ) {
95- s , err := settings . Load ( cf )
96-
64+ // PermDelete removes a user from an app or revokes admin privileges.
65+ func ( d * DryccCmd ) PermDelete ( userPermID uint64 ) error {
66+ s , err := settings . Load ( d . ConfigFile )
9767 if err != nil {
98- return nil , "" , err
68+ return err
9969 }
70+ d .Printf ("Removing user perm with id %d... " , userPermID )
71+ err = perms .Delete (s .Client , fmt .Sprintf ("%d" , userPermID ))
10072
101- if ! admin && appID == "" {
102- appID , err = git .DetectAppName (git .DefaultCmd , s .Client .ControllerURL .Host )
103-
104- if err != nil {
105- return nil , "" , err
106- }
73+ if d .checkAPICompatibility (s .Client , err ) != nil {
74+ return err
10775 }
108-
109- return s , appID , err
76+ d . Println ( "done" )
77+ return nil
11078}
0 commit comments