make use of IsAdmin
parent
362ca0fa19
commit
a92c972d43
|
@ -9,6 +9,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
townuser "git.tilde.town/tildetown/town/user"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -30,24 +31,7 @@ func isAdmin() (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to get information about current user: %w", err)
|
return false, fmt.Errorf("failed to get information about current user: %w", err)
|
||||||
}
|
}
|
||||||
|
return townuser.IsAdmin(u)
|
||||||
adminGroup, err := user.LookupGroup("admin")
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("failed to get admin group info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
groupIds, err := u.GroupIds()
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("failed to get groups info: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, groupId := range groupIds {
|
|
||||||
if groupId == adminGroup.Gid {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCommands(targetCmd *cobra.Command, path string) error {
|
func parseCommands(targetCmd *cobra.Command, path string) error {
|
||||||
|
|
Loading…
Reference in New Issue