diff --git a/pkg/api/v1alpha1/application_types.go b/pkg/api/v1alpha1/application_types.go index 11e3315..609ce74 100644 --- a/pkg/api/v1alpha1/application_types.go +++ b/pkg/api/v1alpha1/application_types.go @@ -147,7 +147,9 @@ func (r *Router) getApplicationType(c *gin.Context) { return } - c.JSON(http.StatusOK, ApplicationType{app}) + c.JSON(http.StatusOK, ApplicationType{ + ApplicationType: app, + }) } // createApplicationType creates an application type in the database diff --git a/pkg/api/v1alpha1/applications.go b/pkg/api/v1alpha1/applications.go index d761514..de8bdbe 100644 --- a/pkg/api/v1alpha1/applications.go +++ b/pkg/api/v1alpha1/applications.go @@ -151,7 +151,10 @@ func (r *Router) getApplication(c *gin.Context) { return } - c.JSON(http.StatusOK, Application{app, app.R.Type}) + c.JSON(http.StatusOK, Application{ + Application: app, + Type: app.R.Type, + }) } // createApplication creates an application in the database diff --git a/pkg/api/v1alpha1/authenticated_user.go b/pkg/api/v1alpha1/authenticated_user.go index 58736ec..a91c19c 100644 --- a/pkg/api/v1alpha1/authenticated_user.go +++ b/pkg/api/v1alpha1/authenticated_user.go @@ -35,6 +35,7 @@ type AuthenticatedUserGroup struct { Organizations models.OrganizationSlice `json:"organizations"` Applications models.ApplicationSlice `json:"applications"` Admin bool `json:"admin"` + Direct bool `json:"direct"` } // AuthenticatedUserRequests is a list of application and member requests for the authenticated user @@ -73,7 +74,12 @@ func (r *Router) getAuthenticatedUser(c *gin.Context) { if ctxUser.R == nil { c.JSON(http.StatusOK, AuthenticatedUser{ - User: &User{ctxUser, []string{}, []string{}}, + User: &User{ + User: ctxUser, + Memberships: []string{}, + MembershipsDirect: []string{}, + MembershipRequests: []string{}, + }, Admin: *ctxAdmin, }) @@ -87,8 +93,15 @@ func (r *Router) getAuthenticatedUser(c *gin.Context) { } memberships := make([]string, len(enumeratedMemberships)) + + membershipsDirect := make([]string, 0) + for i, m := range enumeratedMemberships { memberships[i] = m.GroupID + + if m.Direct { + membershipsDirect = append(membershipsDirect, m.GroupID) + } } requests := make([]string, len(ctxUser.R.GroupMembershipRequests)) @@ -97,7 +110,12 @@ func (r *Router) getAuthenticatedUser(c *gin.Context) { } c.JSON(http.StatusOK, AuthenticatedUser{ - User: &User{ctxUser, memberships, requests}, + User: &User{ + User: ctxUser, + Memberships: memberships, + MembershipsDirect: membershipsDirect, + MembershipRequests: requests, + }, Admin: *ctxAdmin, }) } @@ -112,6 +130,8 @@ func (r *Router) getAuthenticatedUserGroups(c *gin.Context) { var userAdminGroups []string + var userDirectGroups []string + enumeratedMemberships, err := dbtools.GetMembershipsForUser(c, r.DB.DB, ctxUser.ID, false) if err != nil { sendError(c, http.StatusInternalServerError, "error enumerating group membership: "+err.Error()) @@ -125,6 +145,10 @@ func (r *Router) getAuthenticatedUserGroups(c *gin.Context) { if g.IsAdmin { userAdminGroups = append(userAdminGroups, g.GroupID) } + + if g.Direct { + userDirectGroups = append(userDirectGroups, g.GroupID) + } } groups, err := models.Groups( @@ -152,7 +176,13 @@ func (r *Router) getAuthenticatedUserGroups(c *gin.Context) { apps = append(apps, a.R.Application) } - userGroups = append(userGroups, AuthenticatedUserGroup{g, orgs, apps, contains(userAdminGroups, g.ID)}) + userGroups = append(userGroups, AuthenticatedUserGroup{ + Group: g, + Organizations: orgs, + Applications: apps, + Admin: contains(userAdminGroups, g.ID), + Direct: contains(userDirectGroups, g.ID), + }) } c.JSON(http.StatusOK, userGroups) @@ -300,7 +330,10 @@ func (r *Router) getAuthenticatedUserGroupRequests(c *gin.Context) { Note: m.Note, } - memberRequests[i] = AuthenticatedUserGroupMemberRequest{&gmr, false} + memberRequests[i] = AuthenticatedUserGroupMemberRequest{ + GroupMemberRequest: &gmr, + Admin: false, + } } applicationRequests := make([]AuthenticatedUserGroupApplicationRequest, len(ctxUser.R.RequesterUserGroupApplicationRequests)) @@ -326,7 +359,9 @@ func (r *Router) getAuthenticatedUserGroupRequests(c *gin.Context) { UpdatedAt: a.UpdatedAt, } - applicationRequests[i] = AuthenticatedUserGroupApplicationRequest{&gar} + applicationRequests[i] = AuthenticatedUserGroupApplicationRequest{ + GroupApplicationRequest: &gar, + } } c.JSON(http.StatusOK, AuthenticatedUserRequests{ diff --git a/pkg/api/v1alpha1/groups.go b/pkg/api/v1alpha1/groups.go index daa82cc..469efe1 100644 --- a/pkg/api/v1alpha1/groups.go +++ b/pkg/api/v1alpha1/groups.go @@ -22,6 +22,7 @@ import ( type Group struct { *models.Group Members []string `json:"members,omitempty"` + MembersDirect []string `json:"members_direct,omitempty"` MembershipRequests []string `json:"membership_requests,omitempty"` Organizations []string `json:"organizations"` Applications []string `json:"applications"` @@ -109,8 +110,15 @@ func (r *Router) getGroup(c *gin.Context) { } members := make([]string, len(enumeratedMembers)) + + membersDirect := make([]string, 0) + for i, m := range enumeratedMembers { members[i] = m.UserID + + if m.Direct { + membersDirect = append(membersDirect, m.UserID) + } } requests := make([]string, len(group.R.GroupMembershipRequests)) @@ -128,7 +136,14 @@ func (r *Router) getGroup(c *gin.Context) { applications[i] = o.R.Application.ID } - c.JSON(http.StatusOK, Group{group, members, requests, organizations, applications}) + c.JSON(http.StatusOK, Group{ + Group: group, + Members: members, + MembersDirect: membersDirect, + MembershipRequests: requests, + Organizations: organizations, + Applications: applications, + }) } func createGroupRequestValidator(group *models.Group) (string, error) { diff --git a/pkg/api/v1alpha1/organizations.go b/pkg/api/v1alpha1/organizations.go index 25f4e5d..91f6a39 100644 --- a/pkg/api/v1alpha1/organizations.go +++ b/pkg/api/v1alpha1/organizations.go @@ -142,7 +142,9 @@ func (r *Router) getOrganization(c *gin.Context) { return } - c.JSON(http.StatusOK, Organization{org}) + c.JSON(http.StatusOK, Organization{ + Organization: org, + }) } // createOrganization creates an org in the database diff --git a/pkg/api/v1alpha1/users.go b/pkg/api/v1alpha1/users.go index 1ed41f2..82f57e7 100644 --- a/pkg/api/v1alpha1/users.go +++ b/pkg/api/v1alpha1/users.go @@ -35,6 +35,7 @@ var permittedListUsersParams = []string{"external_id", "email"} type User struct { *models.User Memberships []string `json:"memberships,omitempty"` + MembershipsDirect []string `json:"memberships_direct,omitempty"` MembershipRequests []string `json:"membership_requests,omitempty"` } @@ -135,8 +136,15 @@ func (r *Router) getUser(c *gin.Context) { } memberships := make([]string, len(enumeratedMemberships)) + + membershipsDirect := make([]string, 0) + for i, m := range enumeratedMemberships { memberships[i] = m.GroupID + + if m.Direct { + membershipsDirect = append(membershipsDirect, m.GroupID) + } } requests := make([]string, len(user.R.GroupMembershipRequests)) @@ -144,7 +152,12 @@ func (r *Router) getUser(c *gin.Context) { requests[i] = r.GroupID } - c.JSON(http.StatusOK, User{user, memberships, requests}) + c.JSON(http.StatusOK, User{ + User: user, + Memberships: memberships, + MembershipsDirect: membershipsDirect, + MembershipRequests: requests, + }) } // createUser creates a user in the database