orgAssignment extracts information from URL parameters to retrieve the organization or team.
(args ...bool)
| 72 | |
| 73 | // orgAssignment extracts information from URL parameters to retrieve the organization or team. |
| 74 | func orgAssignment(args ...bool) macaron.Handler { |
| 75 | var ( |
| 76 | assignOrg bool |
| 77 | assignTeam bool |
| 78 | ) |
| 79 | if len(args) > 0 { |
| 80 | assignOrg = args[0] |
| 81 | } |
| 82 | if len(args) > 1 { |
| 83 | assignTeam = args[1] |
| 84 | } |
| 85 | return func(c *context.APIContext) { |
| 86 | c.Org = new(context.APIOrganization) |
| 87 | |
| 88 | var err error |
| 89 | if assignOrg { |
| 90 | c.Org.Organization, err = database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":orgname")) |
| 91 | if err != nil { |
| 92 | c.NotFoundOrError(err, "get organization by name") |
| 93 | return |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if assignTeam { |
| 98 | c.Org.Team, err = database.GetTeamByID(c.ParamsInt64(":teamid")) |
| 99 | if err != nil { |
| 100 | c.NotFoundOrError(err, "get team by ID") |
| 101 | return |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // reqToken makes sure the context user is authorized via access token. |
| 108 | func reqToken() macaron.Handler { |
no test coverage detected