Add --state and --contract-ended flags to CLI user list

Replace the --active boolean flag with two explicit filters:
--state (ACTIVE/INACTIVE) and --contract-ended (true/false).
Also add state filter support to the console GraphQL API.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 11:55:49 +04:00
parent 272f63828f
commit 5988070a42
3 changed files with 35 additions and 12 deletions

View File

@@ -61,12 +61,13 @@ type profile struct {
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
var (
flagOrg string
flagLimit int
flagOrder string
flagOrderDir string
flagActive bool
flagOutput *string
flagOrg string
flagLimit int
flagOrder string
flagOrderDir string
flagContractEnded string
flagState string
flagOutput *string
)
cmd := &cobra.Command{
@@ -76,8 +77,11 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
Example: ` # List users in the default organization
prb user list
# List only active users as JSON
prb user ls --active --json`,
# List only active users
prb user ls --state ACTIVE
# List users whose contract has ended
prb user ls --contract-ended true`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmdutil.ValidateOutputFlag(flagOutput); err != nil {
@@ -124,10 +128,24 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
}
}
if flagActive {
variables["filter"] = map[string]any{
"contractEnded": false,
filter := map[string]any{}
if flagContractEnded != "" {
if err := cmdutil.ValidateEnum("contract-ended", flagContractEnded, []string{"true", "false"}); err != nil {
return err
}
filter["contractEnded"] = flagContractEnded == "true"
}
if flagState != "" {
if err := cmdutil.ValidateEnum("state", flagState, []string{"ACTIVE", "INACTIVE"}); err != nil {
return err
}
filter["state"] = flagState
}
if len(filter) > 0 {
variables["filter"] = filter
}
profiles, totalCount, err := api.Paginate(
@@ -210,7 +228,8 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmd.Flags().IntVarP(&flagLimit, "limit", "L", 30, "Maximum number of users to list")
cmd.Flags().StringVar(&flagOrder, "order-by", "", "Order by field (FULL_NAME, CREATED_AT, KIND)")
cmd.Flags().StringVar(&flagOrderDir, "order-direction", "DESC", "Sort direction (ASC, DESC)")
cmd.Flags().BoolVar(&flagActive, "active", false, "Show only users with active or no contract")
cmd.Flags().StringVar(&flagContractEnded, "contract-ended", "", "Filter by contract status (true or false)")
cmd.Flags().StringVar(&flagState, "state", "", "Filter by profile state (ACTIVE or INACTIVE)")
flagOutput = cmdutil.AddOutputFlag(cmd)
return cmd

View File

@@ -53,6 +53,7 @@ input ProfileOrder
input ProfileFilter {
contractEnded: Boolean
state: ProfileState
}
type ProfileConnection

View File

@@ -124,6 +124,9 @@ func (r *organizationResolver) Profiles(ctx context.Context, obj *types.Organiza
filters := coredata.NewMembershipProfileFilter(nil).WithMembership()
if filter != nil {
filters = coredata.NewMembershipProfileFilter(filter.ContractEnded).WithMembership()
if filter.State != nil {
filters.WithState(*filter.State)
}
}
pageOrderBy := page.OrderBy[coredata.MembershipProfileOrderField]{