summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2023-04-04 21:35:31 +0800
committerGitHub <noreply@github.com>2023-04-04 21:35:31 +0800
commit6b0df6d8da76d77a9b5c42dcfa78dbfe197fd56d (patch)
tree6d78855ec0f8e4bed42a0ae7587687a4755b6536 /routers/api/v1
parentd149093ce3c32503b95c66208de6cb5861e4e666 (diff)
downloadgitea-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')
-rw-r--r--routers/api/v1/api.go5
-rw-r--r--routers/api/v1/org/org.go67
-rw-r--r--routers/api/v1/org/team.go53
-rw-r--r--routers/api/v1/repo/repo.go57
-rw-r--r--routers/api/v1/swagger/activity.go15
-rw-r--r--routers/api/v1/user/user.go57
6 files changed, 254 insertions, 0 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 21797bd1a0..9510b17e2d 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -754,6 +754,8 @@ func Routes(ctx gocontext.Context) *web.Route {
Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken)
m.Combo("/{id}").Delete(user.DeleteAccessToken)
}, reqBasicAuth())
+
+ m.Get("/activities/feeds", user.ListUserActivityFeeds)
}, context_service.UserAssignmentAPI())
})
@@ -1177,6 +1179,7 @@ func Routes(ctx gocontext.Context) *web.Route {
m.Get("/issue_config", context.ReferencesGitRepo(), repo.GetIssueConfig)
m.Get("/issue_config/validate", context.ReferencesGitRepo(), repo.ValidateIssueConfig)
m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages)
+ m.Get("/activities/feeds", repo.ListRepoActivityFeeds)
}, repoAssignment())
})
@@ -1234,6 +1237,7 @@ func Routes(ctx gocontext.Context) *web.Route {
Patch(bind(api.EditHookOption{}), org.EditHook).
Delete(org.DeleteHook)
}, reqToken(auth_model.AccessTokenScopeAdminOrgHook), reqOrgOwnership(), reqWebhooksEnabled())
+ m.Get("/activities/feeds", org.ListOrgActivityFeeds)
}, orgAssignment(true))
m.Group("/teams/{teamid}", func() {
m.Combo("").Get(reqToken(auth_model.AccessTokenScopeReadOrg), org.GetTeam).
@@ -1253,6 +1257,7 @@ func Routes(ctx gocontext.Context) *web.Route {
Delete(reqToken(auth_model.AccessTokenScopeWriteOrg), org.RemoveTeamRepository).
Get(reqToken(auth_model.AccessTokenScopeReadOrg), org.GetTeamRepo)
})
+ m.Get("/activities/feeds", org.ListTeamActivityFeeds)
}, orgAssignment(false, true), reqToken(""), reqTeamMembership())
m.Group("/admin", func() {
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))
+}
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 597f846206..50439251cc 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -9,6 +9,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
@@ -792,3 +793,55 @@ func SearchTeam(ctx *context.APIContext) {
"data": apiTeams,
})
}
+
+func ListTeamActivityFeeds(ctx *context.APIContext) {
+ // swagger:operation GET /teams/{id}/activities/feeds organization orgListTeamActivityFeeds
+ // ---
+ // summary: List a team's activity feeds
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: id
+ // in: path
+ // description: id of the team
+ // type: integer
+ // format: int64
+ // 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"
+
+ listOptions := utils.GetListOptions(ctx)
+
+ opts := activities_model.GetFeedsOptions{
+ RequestedTeam: ctx.Org.Team,
+ Actor: ctx.Doer,
+ IncludePrivate: true,
+ 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))
+}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 60e71495e8..48ace3a8e0 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -10,6 +10,7 @@ import (
"strings"
"time"
+ 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"
@@ -1199,3 +1200,59 @@ func ValidateIssueConfig(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, api.IssueConfigValidation{Valid: false, Message: err.Error()})
}
}
+
+func ListRepoActivityFeeds(ctx *context.APIContext) {
+ // swagger:operation GET /repos/{owner}/{repo}/activities/feeds repository repoListActivityFeeds
+ // ---
+ // summary: List a repository's activity feeds
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: owner
+ // in: path
+ // description: owner of the repo
+ // type: string
+ // required: true
+ // - name: repo
+ // in: path
+ // description: name of the repo
+ // 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"
+
+ listOptions := utils.GetListOptions(ctx)
+
+ opts := activities_model.GetFeedsOptions{
+ RequestedRepo: ctx.Repo.Repository,
+ Actor: ctx.Doer,
+ IncludePrivate: true,
+ 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))
+}
diff --git a/routers/api/v1/swagger/activity.go b/routers/api/v1/swagger/activity.go
new file mode 100644
index 0000000000..95e1ba9035
--- /dev/null
+++ b/routers/api/v1/swagger/activity.go
@@ -0,0 +1,15 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package swagger
+
+import (
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+// ActivityFeedsList
+// swagger:response ActivityFeedsList
+type swaggerActivityFeedsList struct {
+ // in:body
+ Body []api.Activity `json:"body"`
+}
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 6fd4b3a95c..314116962b 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -145,3 +145,60 @@ func GetUserHeatmapData(ctx *context.APIContext) {
}
ctx.JSON(http.StatusOK, heatmap)
}
+
+func ListUserActivityFeeds(ctx *context.APIContext) {
+ // swagger:operation GET /users/{username}/activities/feeds user userListActivityFeeds
+ // ---
+ // summary: List a user's activity feeds
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: username
+ // in: path
+ // description: username of user
+ // type: string
+ // required: true
+ // - name: only-performed-by
+ // in: query
+ // description: if true, only show actions performed by the requested user
+ // type: boolean
+ // - 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 := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
+ listOptions := utils.GetListOptions(ctx)
+
+ opts := activities_model.GetFeedsOptions{
+ RequestedUser: ctx.ContextUser,
+ Actor: ctx.Doer,
+ IncludePrivate: includePrivate,
+ OnlyPerformedBy: ctx.FormBool("only-performed-by"),
+ 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))
+}