648389968740b5f9ed557d3bf81c7394931f29ce

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(server): reduce perms to collab when creating/deleting repos

Diff

  1diff --git a/server/cmd/collab.go b/server/cmd/collab.go
  2index 9426a975a98b22e10b66b836daf47e489e0dcf9c..08baf5a065cec13748c99cbae5c1a8528b4ba9de 100644
  3--- a/server/cmd/collab.go
  4+++ b/server/cmd/collab.go
  5@@ -25,7 +25,7 @@ func collabAddCommand() *cobra.Command {
  6 		Use:               "add REPOSITORY USERNAME",
  7 		Short:             "Add a collaborator to a repo",
  8 		Args:              cobra.ExactArgs(2),
  9-		PersistentPreRunE: checkIfAdmin,
 10+		PersistentPreRunE: checkIfCollab,
 11 		RunE: func(cmd *cobra.Command, args []string) error {
 12 			cfg, _ := fromContext(cmd)
 13 			repo := args[0]
 14@@ -43,7 +43,7 @@ func collabRemoveCommand() *cobra.Command {
 15 		Use:               "remove REPOSITORY USERNAME",
 16 		Args:              cobra.ExactArgs(2),
 17 		Short:             "Remove a collaborator from a repo",
 18-		PersistentPreRunE: checkIfAdmin,
 19+		PersistentPreRunE: checkIfCollab,
 20 		RunE: func(cmd *cobra.Command, args []string) error {
 21 			cfg, _ := fromContext(cmd)
 22 			repo := args[0]
 23diff --git a/server/cmd/create.go b/server/cmd/create.go
 24index 259406d1424078f9d6e9646e509dba3bf989e026..1c3ae6787d63eded8d07d655dde87600db41536a 100644
 25--- a/server/cmd/create.go
 26+++ b/server/cmd/create.go
 27@@ -10,12 +10,13 @@ func createCommand() *cobra.Command {
 28 	var private bool
 29 	var description string
 30 	var projectName string
 31+	var hidden bool
 32 
 33 	cmd := &cobra.Command{
 34 		Use:               "create REPOSITORY",
 35 		Short:             "Create a new repository",
 36 		Args:              cobra.ExactArgs(1),
 37-		PersistentPreRunE: checkIfAdmin,
 38+		PersistentPreRunE: checkIfCollab,
 39 		RunE: func(cmd *cobra.Command, args []string) error {
 40 			cfg, _ := fromContext(cmd)
 41 			name := args[0]
 42@@ -23,6 +24,7 @@ func createCommand() *cobra.Command {
 43 				Private:     private,
 44 				Description: description,
 45 				ProjectName: projectName,
 46+				Hidden:      hidden,
 47 			}); err != nil {
 48 				return err
 49 			}
 50@@ -33,6 +35,7 @@ func createCommand() *cobra.Command {
 51 	cmd.Flags().BoolVarP(&private, "private", "p", false, "make the repository private")
 52 	cmd.Flags().StringVarP(&description, "description", "d", "", "set the repository description")
 53 	cmd.Flags().StringVarP(&projectName, "name", "n", "", "set the project name")
 54+	cmd.Flags().BoolVarP(&hidden, "hidden", "H", false, "hide the repository from the list")
 55 
 56 	return cmd
 57 }
 58diff --git a/server/cmd/delete.go b/server/cmd/delete.go
 59index 7c335ac6c403e6ec46eedbb9aa6d8177692a6be3..fb3f1dbdf1a8d976133de9c742447d51b9576975 100644
 60--- a/server/cmd/delete.go
 61+++ b/server/cmd/delete.go
 62@@ -8,7 +8,7 @@ func deleteCommand() *cobra.Command {
 63 		Aliases:           []string{"del", "remove", "rm"},
 64 		Short:             "Delete a repository",
 65 		Args:              cobra.ExactArgs(1),
 66-		PersistentPreRunE: checkIfAdmin,
 67+		PersistentPreRunE: checkIfCollab,
 68 		RunE: func(cmd *cobra.Command, args []string) error {
 69 			cfg, _ := fromContext(cmd)
 70 			name := args[0]
 71diff --git a/server/cmd/import.go b/server/cmd/import.go
 72index 7135239f15dac10fc9ab8bf1b24d9c30cb9f2568..8edee1a55420184fe237672d931b63c73631ba8c 100644
 73--- a/server/cmd/import.go
 74+++ b/server/cmd/import.go
 75@@ -16,7 +16,7 @@ func importCommand() *cobra.Command {
 76 		Use:               "import REPOSITORY REMOTE",
 77 		Short:             "Import a new repository from remote",
 78 		Args:              cobra.ExactArgs(2),
 79-		PersistentPreRunE: checkIfAdmin,
 80+		PersistentPreRunE: checkIfCollab,
 81 		RunE: func(cmd *cobra.Command, args []string) error {
 82 			cfg, _ := fromContext(cmd)
 83 			name := args[0]
 84diff --git a/server/cmd/list.go b/server/cmd/list.go
 85index 4b5a2a57cc06024a7a41b07723e21079a00e47e9..9cfb936a5f2428c59259e12110456ee200128390 100644
 86--- a/server/cmd/list.go
 87+++ b/server/cmd/list.go
 88@@ -7,6 +7,8 @@ import (
 89 
 90 // listCommand returns a command that list file or directory at path.
 91 func listCommand() *cobra.Command {
 92+	var all bool
 93+
 94 	listCmd := &cobra.Command{
 95 		Use:     "list",
 96 		Aliases: []string{"ls"},
 97@@ -20,11 +22,16 @@ func listCommand() *cobra.Command {
 98 			}
 99 			for _, r := range repos {
100 				if cfg.Backend.AccessLevelByPublicKey(r.Name(), s.PublicKey()) >= backend.ReadOnlyAccess {
101-					cmd.Println(r.Name())
102+					if !r.IsHidden() || all {
103+						cmd.Println(r.Name())
104+					}
105 				}
106 			}
107 			return nil
108 		},
109 	}
110+
111+	listCmd.Flags().BoolVarP(&all, "all", "a", false, "List all repositories")
112+
113 	return listCmd
114 }