diff options
author | Zettat123 <zettat123@gmail.com> | 2023-04-04 21:35:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 21:35:31 +0800 |
commit | 6b0df6d8da76d77a9b5c42dcfa78dbfe197fd56d (patch) | |
tree | 6d78855ec0f8e4bed42a0ae7587687a4755b6536 /routers/api/v1/org/org.go | |
parent | d149093ce3c32503b95c66208de6cb5861e4e666 (diff) | |
download | gitea-6b0df6d8da76d77a9b5c42dcfa78dbfe197fd56d.tar.gz gitea-6b0df6d8da76d77a9b5c42dcfa78dbfe197fd56d.zip |
Add activity feeds API (#23494)
Close #5666
Add APIs for getting activity feeds.
Diffstat (limited to 'routers/api/v1/org/org.go')
-rw-r--r-- | routers/api/v1/org/org.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index 75420dcc43..4e30ad1762 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -7,6 +7,7 @@ package org import ( "net/http" + activities_model "code.gitea.io/gitea/models/activities" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" @@ -370,3 +371,69 @@ func Delete(ctx *context.APIContext) { } ctx.Status(http.StatusNoContent) } + +func ListOrgActivityFeeds(ctx *context.APIContext) { + // swagger:operation GET /orgs/{org}/activities/feeds organization orgListActivityFeeds + // --- + // summary: List an organization's activity feeds + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of the org + // type: string + // required: true + // - name: date + // in: query + // description: the date of the activities to be found + // type: string + // format: date + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results + // type: integer + // responses: + // "200": + // "$ref": "#/responses/ActivityFeedsList" + // "404": + // "$ref": "#/responses/notFound" + + includePrivate := false + if ctx.IsSigned { + if ctx.Doer.IsAdmin { + includePrivate = true + } else { + org := organization.OrgFromUser(ctx.ContextUser) + isMember, err := org.IsOrgMember(ctx.Doer.ID) + if err != nil { + ctx.Error(http.StatusInternalServerError, "IsOrgMember", err) + return + } + includePrivate = isMember + } + } + + listOptions := utils.GetListOptions(ctx) + + opts := activities_model.GetFeedsOptions{ + RequestedUser: ctx.ContextUser, + Actor: ctx.Doer, + IncludePrivate: includePrivate, + Date: ctx.FormString("date"), + ListOptions: listOptions, + } + + feeds, count, err := activities_model.GetFeeds(ctx, opts) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetFeeds", err) + return + } + ctx.SetTotalCountHeader(count) + + ctx.JSON(http.StatusOK, convert.ToActivities(ctx, feeds, ctx.Doer)) +} |