forked from Shiloh/githaven
Merge pull request #1904 from ethantkoenig/fix/org_api
Bug fixes for org member API
This commit is contained in:
commit
a70073e768
@ -53,7 +53,8 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
|||||||
|
|
||||||
// ListMembers list an organization's members
|
// ListMembers list an organization's members
|
||||||
func ListMembers(ctx *context.APIContext) {
|
func ListMembers(ctx *context.APIContext) {
|
||||||
listMembers(ctx, !ctx.Org.Organization.IsOrgMember(ctx.User.ID))
|
publicOnly := ctx.User == nil || !ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
||||||
|
listMembers(ctx, publicOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPublicMembers list an organization's public members
|
// ListPublicMembers list an organization's public members
|
||||||
@ -63,20 +64,21 @@ func ListPublicMembers(ctx *context.APIContext) {
|
|||||||
|
|
||||||
// IsMember check if a user is a member of an organization
|
// IsMember check if a user is a member of an organization
|
||||||
func IsMember(ctx *context.APIContext) {
|
func IsMember(ctx *context.APIContext) {
|
||||||
org := ctx.Org.Organization
|
|
||||||
requester := ctx.User
|
|
||||||
userToCheck := user.GetUserByParams(ctx)
|
userToCheck := user.GetUserByParams(ctx)
|
||||||
if org.IsOrgMember(requester.ID) {
|
if ctx.Written() {
|
||||||
if org.IsOrgMember(userToCheck.ID) {
|
return
|
||||||
|
}
|
||||||
|
if ctx.User != nil && ctx.Org.Organization.IsOrgMember(ctx.User.ID) {
|
||||||
|
if ctx.Org.Organization.IsOrgMember(userToCheck.ID) {
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
} else {
|
} else {
|
||||||
ctx.Status(404)
|
ctx.Status(404)
|
||||||
}
|
}
|
||||||
} else if requester.ID == userToCheck.ID {
|
} else if ctx.User != nil && ctx.User.ID == userToCheck.ID {
|
||||||
ctx.Status(404)
|
ctx.Status(404)
|
||||||
} else {
|
} else {
|
||||||
redirectURL := fmt.Sprintf("%sapi/v1/orgs/%s/public_members/%s",
|
redirectURL := fmt.Sprintf("%sapi/v1/orgs/%s/public_members/%s",
|
||||||
setting.AppURL, org.Name, userToCheck.Name)
|
setting.AppURL, ctx.Org.Organization.Name, userToCheck.Name)
|
||||||
ctx.Redirect(redirectURL, 302)
|
ctx.Redirect(redirectURL, 302)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +86,9 @@ func IsMember(ctx *context.APIContext) {
|
|||||||
// IsPublicMember check if a user is a public member of an organization
|
// IsPublicMember check if a user is a public member of an organization
|
||||||
func IsPublicMember(ctx *context.APIContext) {
|
func IsPublicMember(ctx *context.APIContext) {
|
||||||
userToCheck := user.GetUserByParams(ctx)
|
userToCheck := user.GetUserByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if userToCheck.IsPublicMember(ctx.Org.Organization.ID) {
|
if userToCheck.IsPublicMember(ctx.Org.Organization.ID) {
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
} else {
|
} else {
|
||||||
@ -94,6 +99,9 @@ func IsPublicMember(ctx *context.APIContext) {
|
|||||||
// PublicizeMember make a member's membership public
|
// PublicizeMember make a member's membership public
|
||||||
func PublicizeMember(ctx *context.APIContext) {
|
func PublicizeMember(ctx *context.APIContext) {
|
||||||
userToPublicize := user.GetUserByParams(ctx)
|
userToPublicize := user.GetUserByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if userToPublicize.ID != ctx.User.ID {
|
if userToPublicize.ID != ctx.User.ID {
|
||||||
ctx.Error(403, "", "Cannot publicize another member")
|
ctx.Error(403, "", "Cannot publicize another member")
|
||||||
return
|
return
|
||||||
@ -109,6 +117,9 @@ func PublicizeMember(ctx *context.APIContext) {
|
|||||||
// ConcealMember make a member's membership not public
|
// ConcealMember make a member's membership not public
|
||||||
func ConcealMember(ctx *context.APIContext) {
|
func ConcealMember(ctx *context.APIContext) {
|
||||||
userToConceal := user.GetUserByParams(ctx)
|
userToConceal := user.GetUserByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if userToConceal.ID != ctx.User.ID {
|
if userToConceal.ID != ctx.User.ID {
|
||||||
ctx.Error(403, "", "Cannot conceal another member")
|
ctx.Error(403, "", "Cannot conceal another member")
|
||||||
return
|
return
|
||||||
@ -123,9 +134,11 @@ func ConcealMember(ctx *context.APIContext) {
|
|||||||
|
|
||||||
// DeleteMember remove a member from an organization
|
// DeleteMember remove a member from an organization
|
||||||
func DeleteMember(ctx *context.APIContext) {
|
func DeleteMember(ctx *context.APIContext) {
|
||||||
org := ctx.Org.Organization
|
member := user.GetUserByParams(ctx)
|
||||||
memberID := user.GetUserByParams(ctx).ID
|
if ctx.Written() {
|
||||||
if err := org.RemoveMember(memberID); err != nil {
|
return
|
||||||
|
}
|
||||||
|
if err := ctx.Org.Organization.RemoveMember(member.ID); err != nil {
|
||||||
ctx.Error(500, "RemoveMember", err)
|
ctx.Error(500, "RemoveMember", err)
|
||||||
}
|
}
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
|
Loading…
Reference in New Issue
Block a user