Skip to content

Commit

Permalink
list individuals
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen1024 committed Mar 29, 2021
1 parent f71c315 commit eb40dfb
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
63 changes: 62 additions & 1 deletion controllers/individual-signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package controllers

import (
"fmt"
"strings"

"github.com/opensourceways/app-cla-server/dbmodels"
"github.com/opensourceways/app-cla-server/models"
"github.com/opensourceways/app-cla-server/util"
)

type IndividualSigningController struct {
Expand All @@ -16,7 +18,11 @@ func (this *IndividualSigningController) Prepare() {
if this.isPostRequest() {
this.apiPrepare(PermissionIndividualSigner)
} else {
this.apiPrepare("")
if strings.HasSuffix(this.routerPattern(), "/:platform/:org_repo") {
this.apiPrepare("")
} else {
this.apiPrepare(PermissionOwnerOfOrg)
}
}
}

Expand Down Expand Up @@ -124,3 +130,58 @@ func (this *IndividualSigningController) Check() {
this.sendSuccessResp(map[string]bool{"signed": v})
}
}

// @Title List
// @Description get all the individuals by community manager
// @Param :link_id path string true "link id"
// @Success 200 {object} dbmodels.IndividualSigningBasicInfo
// @Failure 400 missing_url_path_parameter: missing url path parameter
// @Failure 401 missing_token: token is missing
// @Failure 402 unknown_token: token is unknown
// @Failure 403 expired_token: token is expired
// @Failure 404 unauthorized_token: the permission of token is unmatched
// @Failure 405 unknown_link: unkown link id
// @Failure 406 not_yours_org: the link doesn't belong to your community
// @Failure 500 system_error: system error
// @router /:link_id [get]
func (this *IndividualSigningController) List() {
action := "list individuals"
linkID := this.GetString(":link_id")

pl, fr := this.tokenPayloadBasedOnCodePlatform()
if fr != nil {
this.sendFailedResultAsResp(fr, action)
return
}
if fr := pl.isOwnerOfLink(linkID); fr != nil {
this.sendFailedResultAsResp(fr, action)
return
}

r, merr := models.ListIndividualSigning(linkID, "", "")
if merr != nil {
this.sendModelErrorAsResp(merr, action)
return
}

corps, merr := models.ListCorpSignings(linkID, "")
if merr != nil {
this.sendModelErrorAsResp(merr, action)
return
}

m := make(map[string]bool, len(corps))
for i := range corps {
if corps[i].AdminAdded {
m[util.EmailSuffix(corps[i].AdminEmail)] = true
}
}

result := make([]*dbmodels.IndividualSigningBasicInfo, 0, len(r))
for i := range r {
if !m[util.EmailSuffix(r[i].Email)] {
result = append(result, &r[i])
}
}
this.sendSuccessResp(result)
}
5 changes: 4 additions & 1 deletion mongodb/individual-signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func (this *client) IsIndividualSigned(linkID, email string) (bool, dbmodels.IDB
func (this *client) ListIndividualSigning(linkID, corpEmail, claLang string) ([]dbmodels.IndividualSigningBasicInfo, dbmodels.IDBError) {
docFilter := docFilterOfSigning(linkID)

arrayFilter := bson.M{fieldCorpID: genCorpID(corpEmail)}
arrayFilter := bson.M{}
if corpEmail != "" {
arrayFilter[fieldCorpID] = genCorpID(corpEmail)
}
if claLang != "" {
arrayFilter[fieldLang] = claLang
}
Expand Down
9 changes: 9 additions & 0 deletions routers/commentsRouter_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ func init() {
Filters: nil,
Params: nil})

beego.GlobalControllerRouter["github.com/opensourceways/app-cla-server/controllers:IndividualSigningController"] = append(beego.GlobalControllerRouter["github.com/opensourceways/app-cla-server/controllers:IndividualSigningController"],
beego.ControllerComments{
Method: "List",
Router: "/:link_id",
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})

beego.GlobalControllerRouter["github.com/opensourceways/app-cla-server/controllers:IndividualSigningController"] = append(beego.GlobalControllerRouter["github.com/opensourceways/app-cla-server/controllers:IndividualSigningController"],
beego.ControllerComments{
Method: "Post",
Expand Down

0 comments on commit eb40dfb

Please sign in to comment.