Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
remove billing admin role, fixes for user management, usage
Dane Schneider871a49e57daf
diff --git a/app/cli/api/methods.go b/app/cli/api/methods.goindex ecb97fa6..9c11804e 100644--- a/app/cli/api/methods.go+++ b/app/cli/api/methods.go@@ -1132,6 +1132,23 @@ func (a *Api) CreateOrg(req shared.CreateOrgRequest) (*shared.CreateOrgResponse,return &createOrgResponse, nil}+func (a *Api) GetOrgSession() *shared.ApiError {+ serverUrl := getApiHost() + "/orgs/session"+ resp, err := authenticatedFastClient.Get(serverUrl)+ if err != nil {+ return &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error sending request: %v", err)}+ }+ defer resp.Body.Close()++ if resp.StatusCode >= 400 {+ errorBody, _ := io.ReadAll(resp.Body)+ apiErr := handleApiError(resp, errorBody)+ return apiErr+ }++ return nil+}+func (a *Api) ListOrgs() ([]*shared.Org, *shared.ApiError) {serverUrl := getApiHost() + "/orgs"resp, err := authenticatedFastClient.Get(serverUrl)@@ -1402,7 +1419,7 @@ func (a *Api) SignOut() *shared.ApiError {return nil}-func (a *Api) ListUsers() ([]*shared.User, *shared.ApiError) {+func (a *Api) ListUsers() (*shared.ListUsersResponse, *shared.ApiError) {serverUrl := getApiHost() + "/users"resp, err := authenticatedFastClient.Get(serverUrl)if err != nil {@@ -1420,13 +1437,13 @@ func (a *Api) ListUsers() ([]*shared.User, *shared.ApiError) {return nil, apiErr}- var users []*shared.User- err = json.NewDecoder(resp.Body).Decode(&users)+ var r *shared.ListUsersResponse+ err = json.NewDecoder(resp.Body).Decode(&r)if err != nil {return nil, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error decoding response: %v", err)}}- return users, nil+ return r, nil}func (a *Api) ListBranches(planId string) ([]*shared.Branch, *shared.ApiError) {diff --git a/app/cli/auth/account.go b/app/cli/auth/account.goindex 1e75dc1a..8f6de2ff 100644--- a/app/cli/auth/account.go+++ b/app/cli/auth/account.go@@ -119,6 +119,12 @@ func SelectOrSignInOrCreate() error {return fmt.Errorf("error setting auth: %v", err)}+ apiErr = apiClient.GetOrgSession()++ if apiErr != nil {+ return fmt.Errorf("error getting org session: %v", apiErr.Msg)+ }+fmt.Printf("β Signed in as %s | Org: %s\n", color.New(color.Bold, term.ColorHiGreen).Sprintf("<%s> %s", Current.UserName, Current.Email), color.New(term.ColorHiCyan).Sprint(Current.OrgName))fmt.Println()diff --git a/app/cli/cmd/revoke.go b/app/cli/cmd/revoke.goindex 6be1fbfd..69c718b9 100644--- a/app/cli/cmd/revoke.go+++ b/app/cli/cmd/revoke.go@@ -6,6 +6,7 @@ import ("plandex/auth""plandex/term"+ "github.com/davecgh/go-spew/spew""github.com/plandex/plandex/shared""github.com/spf13/cobra")@@ -29,7 +30,7 @@ func revoke(cmd *cobra.Command, args []string) {email = args[0]}- var users []*shared.User+ var userResp *shared.ListUsersResponsevar pendingInvites []*shared.InviteerrCh := make(chan error)@@ -37,7 +38,7 @@ func revoke(cmd *cobra.Command, args []string) {go func() {var err *shared.ApiError- users, err = api.Client.ListUsers()+ userResp, err = api.Client.ListUsers()if err != nil {errCh <- fmt.Errorf("error fetching users: %s", err.Msg)return@@ -74,14 +75,18 @@ func revoke(cmd *cobra.Command, args []string) {labelToEmail := make(map[string]string)// Combine users and invites for selection- combinedList := make([]string, 0, len(users)+len(pendingInvites))- for _, user := range users {+ combinedList := make([]string, 0, len(userResp.Users)+len(pendingInvites))+ for _, user := range userResp.Users {+ spew.Dump(user)+label := fmt.Sprintf("%s <%s>", user.Name, user.Email)labelToEmail[label] = user.EmailcombinedList = append(combinedList, label)emailToUserMap[user.Email] = userInfo{Id: user.Id, IsInvite: false}}for _, invite := range pendingInvites {+ spew.Dump(invite)+label := fmt.Sprintf("%s <%s> (invite pending)", invite.Name, invite.Email)labelToEmail[label] = invite.EmailcombinedList = append(combinedList, label)@@ -97,8 +102,14 @@ func revoke(cmd *cobra.Command, args []string) {email = labelToEmail[selected]}+ if email == "" {+ term.OutputErrorAndExit("No user or invite selected")+ }+// Determine if email belongs to a user or an invite and revoke accordinglyif userInfo, exists := emailToUserMap[email]; exists {+ spew.Dump(userInfo)+if userInfo.IsInvite {if err := api.Client.DeleteInvite(userInfo.Id); err != nil {term.OutputErrorAndExit("Failed to revoke invite: %v", err)diff --git a/app/cli/cmd/users.go b/app/cli/cmd/users.goindex f6331e4a..9e685917 100644--- a/app/cli/cmd/users.go+++ b/app/cli/cmd/users.go@@ -25,7 +25,7 @@ func init() {func listUsersAndInvites(cmd *cobra.Command, args []string) {auth.MustResolveAuthWithOrg()- var users []*shared.User+ var userResp *shared.ListUsersResponsevar pendingInvites []*shared.Invitevar orgRoles []*shared.OrgRole@@ -35,7 +35,7 @@ func listUsersAndInvites(cmd *cobra.Command, args []string) {go func() {var err *shared.ApiError- users, err = api.Client.ListUsers()+ userResp, err = api.Client.ListUsers()if err != nil {errCh <- fmt.Errorf("error fetching users: %s", err.Msg)return@@ -81,14 +81,14 @@ func listUsersAndInvites(cmd *cobra.Command, args []string) {// Display users and pending invites in a tabletable := tablewriter.NewWriter(os.Stdout)- table.SetHeader([]string{"Type", "Email", "Name", "Role", "Status"})+ table.SetHeader([]string{"Email", "Name", "Role", "Status"})- for _, user := range users {- table.Append([]string{"User", user.Email, user.Name, orgRolesById[user.OrgRoleId].Label, "Active"})+ for _, user := range userResp.Users {+ table.Append([]string{user.Email, user.Name, orgRolesById[userResp.OrgUsersByUserId[user.Id].OrgRoleId].Label, "Active"})}for _, invite := range pendingInvites {- table.Append([]string{"Invite", invite.Email, invite.Name, orgRolesById[invite.OrgRoleId].Label, "Pending"})+ table.Append([]string{invite.Email, invite.Name, orgRolesById[invite.OrgRoleId].Label, "Pending"})}table.Render()diff --git a/app/cli/types/api.go b/app/cli/types/api.goindex da4b8d49..b4d60130 100644--- a/app/cli/types/api.go+++ b/app/cli/types/api.go@@ -21,10 +21,11 @@ type ApiClient interface {SignIn(req shared.SignInRequest, customHost string) (*shared.SessionResponse, *shared.ApiError)SignOut() *shared.ApiError+ GetOrgSession() *shared.ApiErrorListOrgs() ([]*shared.Org, *shared.ApiError)CreateOrg(req shared.CreateOrgRequest) (*shared.CreateOrgResponse, *shared.ApiError)- ListUsers() ([]*shared.User, *shared.ApiError)+ ListUsers() (*shared.ListUsersResponse, *shared.ApiError)DeleteUser(userId string) *shared.ApiErrorListOrgRoles() ([]*shared.OrgRole, *shared.ApiError)diff --git a/app/server/db/data_models.go b/app/server/db/data_models.goindex 4ccb3146..1e4fb698 100644--- a/app/server/db/data_models.go+++ b/app/server/db/data_models.go@@ -46,7 +46,6 @@ type User struct {Domain string `db:"domain"`NumNonDraftPlans int `db:"num_non_draft_plans"`IsTrial bool `db:"is_trial"`- OrgRoleId string `db:"org_role_id"`CreatedAt time.Time `db:"created_at"`UpdatedAt time.Time `db:"updated_at"`}@@ -56,7 +55,6 @@ func (user *User) ToApi() *shared.User {Id: user.Id,Name: user.Name,Email: user.Email,- OrgRoleId: user.OrgRoleId,NumNonDraftPlans: user.NumNonDraftPlans,IsTrial: user.IsTrial,}@@ -68,7 +66,7 @@ type Invite struct {Email string `db:"email"`Name string `db:"name"`InviterId string `db:"inviter_id"`- InviteeId string `db:"invitee_id"`+ InviteeId *string `db:"invitee_id"`OrgRoleId string `db:"org_role_id"`AcceptedAt *time.Time `db:"accepted_at"`CreatedAt time.Time `db:"created_at"`@@ -92,11 +90,20 @@ func (invite *Invite) ToApi() *shared.Invite {type OrgUser struct {Id string `db:"id"`OrgId string `db:"org_id"`+ OrgRoleId string `db:"org_role_id"`UserId string `db:"user_id"`CreatedAt time.Time `db:"created_at"`UpdatedAt time.Time `db:"updated_at"`}+func (orgUser *OrgUser) ToApi() *shared.OrgUser {+ return &shared.OrgUser{+ OrgId: orgUser.OrgId,+ OrgRoleId: orgUser.OrgRoleId,+ UserId: orgUser.UserId,+ }+}+type Project struct {Id string `db:"id"`OrgId string `db:"org_id"`diff --git a/app/server/db/invite_helpers.go b/app/server/db/invite_helpers.goindex c7726e63..e3e1d491 100644--- a/app/server/db/invite_helpers.go+++ b/app/server/db/invite_helpers.go@@ -8,7 +8,7 @@ import ()func CreateInvite(invite *Invite, tx *sql.Tx) error {- err := tx.QueryRow("INSERT INTO invites (org_id, email, name, inviter_id) RETURNING id", invite.OrgId, invite.Email, invite.Name, invite.InviterId).Scan(&invite.Id)+ err := tx.QueryRow("INSERT INTO invites (org_id, email, name, inviter_id, org_role_id) VALUES ($1, $2, $3, $4, $5) RETURNING id", invite.OrgId, invite.Email, invite.Name, invite.InviterId, invite.OrgRoleId).Scan(&invite.Id)if err != nil {return fmt.Errorf("error creating invite: %v", err)@@ -32,9 +32,9 @@ func GetInvite(id string) (*Invite, error) {return &invite, nil}-func GetInviteForOrgUser(orgId, userId string) (*Invite, error) {+func GetActiveInviteByEmail(orgId, email string) (*Invite, error) {var invite Invite- err := Conn.Get(&invite, "SELECT * FROM invites WHERE org_id = $1 AND invitee_id = $2", orgId, userId)+ err := Conn.Get(&invite, "SELECT * FROM invites WHERE org_id = $1 AND email = $2 AND accepted_at IS NULL", orgId, email)if err != nil {if err == sql.ErrNoRows {@@ -52,7 +52,7 @@ func ListPendingInvites(orgId string) ([]*Invite, error) {err := Conn.Select(&invites, "SELECT * FROM invites WHERE org_id = $1 AND accepted_at IS NULL", orgId)if err != nil {- return nil, fmt.Errorf("error getting invites for org: %v", err)+ return nil, fmt.Errorf("error getting pending invites for org: %v", err)}return invites, nil@@ -63,7 +63,7 @@ func ListAllInvites(orgId string) ([]*Invite, error) {err := Conn.Select(&invites, "SELECT * FROM invites WHERE org_id = $1", orgId)if err != nil {- return nil, fmt.Errorf("error getting invites for org: %v", err)+ return nil, fmt.Errorf("error getting all invites for org: %v", err)}return invites, nil@@ -74,7 +74,7 @@ func ListAcceptedInvites(orgId string) ([]*Invite, error) {err := Conn.Select(&invites, "SELECT * FROM invites WHERE org_id = $1 AND accepted_at IS NOT NULL", orgId)if err != nil {- return nil, fmt.Errorf("error getting invites for org: %v", err)+ return nil, fmt.Errorf("error getting accepted invites for org: %v", err)}return invites, nil@@ -100,9 +100,9 @@ func DeleteInvite(id string, tx *sql.Tx) error {var err errorif tx == nil {- _, err = tx.Exec(query, id)- } else {_, err = Conn.Exec(query, id)+ } else {+ _, err = tx.Exec(query, id)}if err != nil {@@ -136,7 +136,7 @@ func AcceptInvite(invite *Invite, inviteeId string) error {}// create org user- err = CreateOrgUser(invite.OrgId, invite.InviteeId, invite.OrgRoleId, tx)+ err = CreateOrgUser(invite.OrgId, inviteeId, invite.OrgRoleId, tx)if err != nil {return fmt.Errorf("error creating org user: %v", err)@@ -148,7 +148,7 @@ func AcceptInvite(invite *Invite, inviteeId string) error {return fmt.Errorf("error committing transaction: %v", err)}- invite.InviteeId = inviteeId+ invite.InviteeId = &inviteeIdreturn nil}diff --git a/app/server/db/org_helpers.go b/app/server/db/org_helpers.goindex 841fa77a..d79fe3bc 100644--- a/app/server/db/org_helpers.go+++ b/app/server/db/org_helpers.go@@ -3,8 +3,10 @@ package dbimport ("database/sql""fmt"+ "log""strings"+ "github.com/lib/pq""github.com/plandex/plandex/shared")@@ -31,7 +33,7 @@ func GetAccessibleOrgsForUser(user *User) ([]*Org, error) {if len(orgIds) > 0 {var orgsFromInvites []*Org- err = Conn.Select(&orgsFromInvites, "SELECT * FROM orgs WHERE id IN (?)", strings.Join(orgIds, ","))+ err = Conn.Select(&orgsFromInvites, "SELECT * FROM orgs WHERE id = ANY($1)", pq.Array(orgIds))if err != nil {return nil, fmt.Errorf("error getting orgs from invites: %v", err)}@@ -87,7 +89,13 @@ func CreateOrg(req *shared.CreateOrgRequest, userId string, domain *string, tx *return nil, fmt.Errorf("error creating org: %v", err)}- _, err = tx.Exec("INSERT INTO orgs_users (org_id, user_id) VALUES ($1, $2)", org.Id, userId)+ orgRoleId, err := GetOrgOwnerRoleId()++ if err != nil {+ return nil, fmt.Errorf("error getting org owner role id: %v", err)+ }++ _, err = tx.Exec("INSERT INTO orgs_users (org_id, user_id, org_role_id) VALUES ($1, $2, $3)", org.Id, userId, orgRoleId)if err != nil {return nil, fmt.Errorf("error adding org membership: %v", err)@@ -141,6 +149,8 @@ func AddOrgDomainUsers(orgId, domain string, tx *sql.Tx) error {}func DeleteOrgUser(orgId, userId string, tx *sql.Tx) error {+ log.Printf("Deleting org user, org: %s | user: %s\n", orgId, userId)+_, err := tx.Exec("DELETE FROM orgs_users WHERE org_id = $1 AND user_id = $2", orgId, userId)if err != nil {diff --git a/app/server/db/user_helpers.go b/app/server/db/user_helpers.goindex 443124ac..79a99b7a 100644--- a/app/server/db/user_helpers.go+++ b/app/server/db/user_helpers.go@@ -46,6 +46,32 @@ func GetUsersForDomain(domain string) ([]*User, error) {return users, nil}+func GetOrgUser(userId, orgId string) (*OrgUser, error) {+ var orgUser OrgUser+ err := Conn.Get(&orgUser, "SELECT * FROM orgs_users WHERE user_id = $1 AND org_id = $2", userId, orgId)++ if err != nil {+ if err == sql.ErrNoRows {+ return nil, nil+ }++ return nil, fmt.Errorf("error getting org user: %v", err)+ }++ return &orgUser, nil+}++func ListOrgUsers(orgId string) ([]*OrgUser, error) {+ var orgUsers []*OrgUser+ err := Conn.Select(&orgUsers, "SELECT * FROM orgs_users WHERE org_id = $1", orgId)++ if err != nil {+ return nil, fmt.Errorf("error listing org users: %v", err)+ }++ return orgUsers, nil+}+func ListUsers(orgId string) ([]*User, error) {var users []*Usererr := Conn.Select(&users, "SELECT u.* FROM users u INNER JOIN orgs_users ou ON u.id = ou.user_id WHERE ou.org_id = $1", orgId)diff --git a/app/server/handlers/auth_helpers.go b/app/server/handlers/auth_helpers.goindex 4dc34401..2b0b3472 100644--- a/app/server/handlers/auth_helpers.go+++ b/app/server/handlers/auth_helpers.go@@ -97,7 +97,7 @@ func authenticate(w http.ResponseWriter, r *http.Request, requireOrg bool) *typeif !isMember {// check if there's an invite for this user and accept it if so (adds the user to the org)- invite, err := db.GetInviteForOrgUser(parsed.OrgId, authToken.UserId)+ invite, err := db.GetActiveInviteByEmail(parsed.OrgId, user.Email)if err != nil {log.Printf("error getting invite for org user: %v\n", err)@@ -106,6 +106,8 @@ func authenticate(w http.ResponseWriter, r *http.Request, requireOrg bool) *type}if invite != nil {+ log.Println("accepting invite")+err := db.AcceptInvite(invite, authToken.UserId)if err != nil {diff --git a/app/server/handlers/invites.go b/app/server/handlers/invites.goindex fe6e2bb2..c9f6498c 100644--- a/app/server/handlers/invites.go+++ b/app/server/handlers/invites.go@@ -97,7 +97,7 @@ func InviteUserHandler(w http.ResponseWriter, r *http.Request) {}// ensure invite isn't already active- invite, err := db.GetInviteForOrgUser(auth.OrgId, req.Email)+ invite, err := db.GetActiveInviteByEmail(auth.OrgId, req.Email)if err != nil {log.Printf("Error getting invite: %v\n", err)diff --git a/app/server/handlers/orgs.go b/app/server/handlers/orgs.goindex 28021fcf..314df992 100644--- a/app/server/handlers/orgs.go+++ b/app/server/handlers/orgs.go@@ -152,6 +152,18 @@ func CreateOrgHandler(w http.ResponseWriter, r *http.Request) {w.Write(bytes)}+func GetOrgSessionHandler(w http.ResponseWriter, r *http.Request) {+ log.Println("Received request for GetOrgSessionHandler")++ auth := authenticate(w, r, true)++ if auth == nil {+ return+ }++ log.Println("Successfully got org session")+}+func ListOrgRolesHandler(w http.ResponseWriter, r *http.Request) {log.Println("Received request for ListOrgRolesHandler")diff --git a/app/server/handlers/users.go b/app/server/handlers/users.goindex cde30ee9..ba7433f0 100644--- a/app/server/handlers/users.go+++ b/app/server/handlers/users.go@@ -32,9 +32,32 @@ func ListUsersHandler(w http.ResponseWriter, r *http.Request) {if err != nil {log.Println("Error listing users: ", err)http.Error(w, "Error listing users: "+err.Error(), http.StatusInternalServerError)+ return}- bytes, err := json.Marshal(users)+ apiUsers := make([]*shared.User, 0, len(users))+ for _, user := range users {+ apiUsers = append(apiUsers, user.ToApi())+ }++ orgUsers, err := db.ListOrgUsers(auth.OrgId)+ if err != nil {+ log.Println("Error listing org users: ", err)+ http.Error(w, "Error listing org users: "+err.Error(), http.StatusInternalServerError)+ return+ }++ orgUsersByUserId := make(map[string]*shared.OrgUser)+ for _, orgUser := range orgUsers {+ orgUsersByUserId[orgUser.UserId] = orgUser.ToApi()+ }++ resp := shared.ListUsersResponse{+ Users: apiUsers,+ OrgUsersByUserId: orgUsersByUserId,+ }++ bytes, err := json.Marshal(resp)if err != nil {log.Println("Error marshalling users: ", err)@@ -66,20 +89,22 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {vars := mux.Vars(r)userId := vars["userId"]- user, err := db.GetUser(userId)+ log.Println("userId: ", userId)++ orgUser, err := db.GetOrgUser(userId, auth.OrgId)if err != nil {- log.Printf("Error getting user: %v\n", err)- http.Error(w, "Error getting user: "+err.Error(), http.StatusInternalServerError)+ log.Printf("Error getting org user: %v\n", err)+ http.Error(w, "Error getting org user: "+err.Error(), http.StatusInternalServerError)return}- // ensure current user can invite target user- removePermission := types.Permission(strings.Join([]string{string(types.PermissionRemoveUser), user.OrgRoleId}, "|"))+ // ensure current user can remove target user+ removePermission := types.Permission(strings.Join([]string{string(types.PermissionRemoveUser), orgUser.OrgRoleId}, "|"))if !auth.HasPermission(removePermission) {- log.Printf("User does not have permission to invite user with role: %v\n", user.OrgRoleId)- http.Error(w, "User does not have permission to invite user with role: "+user.OrgRoleId, http.StatusForbidden)+ log.Printf("User does not have permission to remove user with role: %v\n", orgUser.OrgRoleId)+ http.Error(w, "User does not have permission to remove user with role: "+orgUser.OrgRoleId, http.StatusForbidden)return}@@ -106,7 +131,7 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {return}- if user.OrgRoleId == ownerRoleId {+ if orgUser.OrgRoleId == ownerRoleId {numOwners, err := db.NumUsersWithRole(auth.OrgId, ownerRoleId)if err != nil {@@ -141,7 +166,7 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {}}()- err = db.DeleteOrgUser(userId, auth.OrgId, tx)+ err = db.DeleteOrgUser(auth.OrgId, userId, tx)if err != nil {log.Println("Error deleting org user: ", err)@@ -149,7 +174,7 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {return}- invite, err := db.GetInviteForOrgUser(auth.OrgId, userId)+ invite, err := db.GetActiveInviteByEmail(auth.OrgId, auth.User.Email)if err != nil {log.Println("Error getting invite for org user: ", err)@@ -167,5 +192,13 @@ func DeleteOrgUserHandler(w http.ResponseWriter, r *http.Request) {}}+ err = tx.Commit()++ if err != nil {+ log.Println("Error committing transaction: ", err)+ http.Error(w, "Error committing transaction: "+err.Error(), http.StatusInternalServerError)+ return+ }+log.Println("Successfully processed request for DeleteOrgUserHandler")}diff --git a/app/server/migrations/2024032700_remove_billing_admin.down.sql b/app/server/migrations/2024032700_remove_billing_admin.down.sqlnew file mode 100644index 00000000..e69de29bdiff --git a/app/server/migrations/2024032700_remove_billing_admin.up.sql b/app/server/migrations/2024032700_remove_billing_admin.up.sqlnew file mode 100644index 00000000..39fb77f7--- /dev/null+++ b/app/server/migrations/2024032700_remove_billing_admin.up.sql@@ -0,0 +1 @@+DELETE FROM org_roles WHERE name = 'billing_admin';\ No newline at end of filediff --git a/app/server/routes.go b/app/server/routes.goindex 6cef9189..5b64ccac 100644--- a/app/server/routes.go+++ b/app/server/routes.go@@ -35,6 +35,7 @@ func routes() *mux.Router {r.HandleFunc("/accounts", handlers.CreateAccountHandler).Methods("POST")r.HandleFunc("/accounts/convert_trial", handlers.ConvertTrialHandler).Methods("POST")+ r.HandleFunc("/orgs/session", handlers.GetOrgSessionHandler).Methods("GET")r.HandleFunc("/orgs", handlers.ListOrgsHandler).Methods("GET")r.HandleFunc("/orgs", handlers.CreateOrgHandler).Methods("POST")diff --git a/app/server/types/auth.go b/app/server/types/auth.goindex a87a5daa..9fea36d9 100644--- a/app/server/types/auth.go+++ b/app/server/types/auth.go@@ -1,6 +1,9 @@package types-import "plandex-server/db"+import (+ "log"+ "plandex-server/db"+)type ServerAuth struct {AuthToken *db.AuthToken@@ -14,7 +17,14 @@ func (a *ServerAuth) HasPermission(permission Permission) bool {return false}- return a.Permissions[permission]+ log.Println("checking permission", permission)+ // log.Println("permissions", spew.Sdump(a.Permissions))++ _, res := a.Permissions[permission]++ log.Println("has permission:", res)++ return res}type Permission stringdiff --git a/app/shared/data_models.go b/app/shared/data_models.goindex 759f6e81..38aed42a 100644--- a/app/shared/data_models.go+++ b/app/shared/data_models.go@@ -17,10 +17,15 @@ type User struct {Name string `json:"name"`Email string `json:"email"`IsTrial bool `json:"isTrial"`- OrgRoleId string `json:"orgRoleId"`NumNonDraftPlans int `json:"numNonDraftPlans"`}+type OrgUser struct {+ OrgId string `json:"orgId"`+ UserId string `json:"userId"`+ OrgRoleId string `json:"orgRoleId"`+}+type Invite struct {Id string `json:"id"`OrgId string `json:"orgId"`@@ -28,7 +33,7 @@ type Invite struct {Name string `json:"name"`OrgRoleId string `json:"orgRoleId"`InviterId string `json:"inviterId"`- InviteeId string `json:"inviteeId"`+ InviteeId *string `json:"inviteeId"`AcceptedAt *time.Time `json:"acceptedAt"`CreatedAt time.Time `json:"createdAt"`}diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex 2e392fc7..d02c55be 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -204,3 +204,8 @@ type UpdateSettingsRequest struct {type UpdateSettingsResponse struct {Msg string `json:"msg"`}++type ListUsersResponse struct {+ Users []*User `json:"users"`+ OrgUsersByUserId map[string]*OrgUser `json:"orgUsersByUserId"`+}diff --git a/guides/USAGE.md b/guides/USAGE.mdindex e6a0c44b..dd0ba616 100644--- a/guides/USAGE.md+++ b/guides/USAGE.md@@ -1,8 +1,6 @@# Using Plandex π οΈ-## Commands and concepts πͺ--### New plan+## New plan πͺ```bashcd your-project@@ -18,7 +16,7 @@ plandex new -n foo-adapters-componentIf you don't give your plan a name up front, it will be named 'draft' until you give it a task. To keep things tidy, you can only have one active plan named 'draft'. If you create a new draft plan, any existing draft plan will be removed.-### Loading context+## Loading context πAfter creating a plan, load any relevant files, directories, directory layouts, urls, or other data into the plan context.@@ -32,7 +30,7 @@ npm test | plandex load # loads the output of `npm test`npm load -n 'add logging statements to all the code you generate.' # load a note into context```-### Tasks+## Tasks β‘οΈNow give the AI a task to do.@@ -48,7 +46,7 @@ quote> add the needed reducer and action as well. write tests for the new code.'plandex tell --file task.txt # or -f task.txt```-### Changes+## Changes ποΈPlandex will stream the response to your terminal and build up a set of changes along the way. It will continue as long as necessary and create or update as many files as needed to complete the task. You can stop it at any time if it starts going in the wrong direction or if feedback would be helpful.@@ -66,7 +64,7 @@ plandex applyIf you're in a git repo, Plandex will automatically add a commit with a nicely formatted message describing the changes. Any uncommitted changes that were present in your working directory beforehand will be unaffected.-### Rewind+## Rewind βͺIf you want to rewind and try a different approach, you can use `log` to show a list of updates and `rewind` commands to go back in time.@@ -77,7 +75,7 @@ plandex rewind 3 # go back 3 stepsplandex rewind a7c8d66 # rewind to a specific state```-### Branches+## Branches π±If you want to try a different approach but also keep the current one around, you can use branches. Create a new branch before rewinding.@@ -89,7 +87,7 @@ plandex branches # see all branchesplandex delete-branch new-approach # delete a branch```-### Continue+## Continue βΆοΈIf a plan has stopped and you just want to continue where you left off, you can use the `continue` command.@@ -97,7 +95,7 @@ If a plan has stopped and you just want to continue where you left off, you canplandex continue # continue the current plan```-### Background tasks+## Background tasks πIf you want to run a command in the background, use the --bg flag.@@ -113,7 +111,7 @@ plandex connect # select an active plan to connect toplandex stop # select an active plan to stop```-### Context management+## Context management πYou can see the plan's current context with the `ls` command. You can remove context with the `rm` command or clear it all with the `clear` command.@@ -132,7 +130,7 @@ If files in context are modified outside of Plandex, you will be prompted to updplandex update # update files in context```-### Plans+## Plans πWhen you have multiple plans, you can list them with the `plans` command, switch between them with the `cd` command, see the current plan with the `current` command, and delete plans with the `delete-plan` command. Archiving of plans will be added in the future for plans that you want to keep around but aren't currently working on.@@ -147,7 +145,7 @@ plandex delete-plan some-plan # delete a plan by nameplandex delete-plan 4 # delete a plan by number in the `plandex plans` list```-### Conversation history+## Conversation history π¬You can see the full conversation history with the `convo` command.@@ -155,11 +153,11 @@ You can see the full conversation history with the `convo` command.plandex convo # show the full conversation history```-### Conversation summaries+## Conversation summaries π€Every time the AI model replies, Plandex will summarize the conversation so far in the background and store the summary in case it's needed later. When the conversation size in tokens exceeds the model's limit, Plandex will automatically replace some number of older messages with the corresponding summary. It will summarize as many messages as necessary to keep the conversation size under the limit.-### Model settings+## Model settings π§You can see the current AI models and model settings with the `models` command and change them with the `set-model` command.@@ -174,7 +172,7 @@ plandex set-model max-convo-tokens 20000 # set how large the conversation can gModel changes are versioned and can be rewound or applied to a branch just like any other change.-### .plandex directory and teams+## .plandex directory and orgs π₯When you run `plandex new` for the first time in any directory, Plandex will create a `.plandex` directory there for light project-level config.@@ -183,7 +181,7 @@ If multiple people are using Plandex with the same project, you should either:- Put `.plandex/` in `.gitignore`- **Commit** the `.plandex` directory and get everyone into the same **org** in Plandex.-### Orgs+### OrgsWhen creating a new org, you have the option of automatically granting access to anyone with an email address on your domain. If you choose not to do this, or you want to invite someone from outside your email domain, you can use `plandex invite`.@@ -195,7 +193,7 @@ To revoke an invite or remove a user, use `plandex revoke`.Orgs will be the basis for plan sharing and collaboration in future releases.-### Directories+## Directories πSo far, we've assumed you're running `plandex new` to create plans in your project's root directory. While that is the most common use case, it can be useful to create plans in subdirectories of your project too. That's because context file paths in Plandex are specified relative to the directory where the plan was created. So if you're working on a plan for just one part of your project, you might want to create the plan in a subdirectory in order to shorten paths when loading context or referencing files in your prompts. This can also help with plan organization if you have a lot of plans.@@ -224,7 +222,7 @@ plandex load ../file.go # loads file.go from parent directoryplandex load ../sibling-dir/test.go # loads test.go from sibling directory```-### Ignoring files+## Ignoring files πPlandex respects `.gitignore` and won't load any files that you're ignoring. You can also add a `.plandexignore` file with ignore patterns to any directory.