Restricted users (#4334): initial implementation
* Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se>
This commit is contained in:
@@ -233,6 +233,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
u.MaxRepoCreation = form.MaxRepoCreation
|
||||
u.IsActive = form.Active
|
||||
u.IsAdmin = form.Admin
|
||||
u.IsRestricted = form.Restricted
|
||||
u.AllowGitHook = form.AllowGitHook
|
||||
u.AllowImportLocal = form.AllowImportLocal
|
||||
u.AllowCreateOrganization = form.AllowCreateOrganization
|
||||
|
||||
@@ -77,8 +77,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
OwnerID: ctx.User.ID,
|
||||
TopicOnly: false,
|
||||
Collaborate: util.OptionalBoolNone,
|
||||
UserIsAdmin: ctx.IsUserSiteAdmin(),
|
||||
UserID: ctx.User.ID,
|
||||
Actor: ctx.User,
|
||||
OrderBy: models.SearchOrderByRecentUpdated,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -126,6 +126,7 @@ func Search(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := &models.SearchRepoOptions{
|
||||
Actor: ctx.User,
|
||||
Keyword: strings.Trim(ctx.Query("q"), " "),
|
||||
OwnerID: ctx.QueryInt64("uid"),
|
||||
PriorityOwnerID: ctx.QueryInt64("priority_owner_id"),
|
||||
@@ -135,8 +136,6 @@ func Search(ctx *context.APIContext) {
|
||||
Collaborate: util.OptionalBoolNone,
|
||||
Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")),
|
||||
Template: util.OptionalBoolNone,
|
||||
UserIsAdmin: ctx.IsUserSiteAdmin(),
|
||||
UserID: ctx.Data["SignedUserID"].(int64),
|
||||
StarredByID: ctx.QueryInt64("starredBy"),
|
||||
IncludeDescription: ctx.QueryBool("includeDesc"),
|
||||
}
|
||||
|
||||
@@ -71,10 +71,11 @@ func Home(ctx *context.Context) {
|
||||
|
||||
// RepoSearchOptions when calling search repositories
|
||||
type RepoSearchOptions struct {
|
||||
OwnerID int64
|
||||
Private bool
|
||||
PageSize int
|
||||
TplName base.TplName
|
||||
OwnerID int64
|
||||
Private bool
|
||||
Restricted bool
|
||||
PageSize int
|
||||
TplName base.TplName
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -135,6 +136,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||
ctx.Data["TopicOnly"] = topicOnly
|
||||
|
||||
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
|
||||
Actor: ctx.User,
|
||||
Page: page,
|
||||
PageSize: opts.PageSize,
|
||||
OrderBy: orderBy,
|
||||
@@ -189,6 +191,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
|
||||
if opts.Page <= 1 {
|
||||
opts.Page = 1
|
||||
}
|
||||
opts.Actor = ctx.User
|
||||
|
||||
var (
|
||||
users []*models.User
|
||||
@@ -260,16 +263,10 @@ func ExploreOrganizations(ctx *context.Context) {
|
||||
ctx.Data["PageIsExploreOrganizations"] = true
|
||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
|
||||
var ownerID int64
|
||||
if ctx.User != nil && !ctx.User.IsAdmin {
|
||||
ownerID = ctx.User.ID
|
||||
}
|
||||
|
||||
RenderUserSearch(ctx, &models.SearchUserOptions{
|
||||
Type: models.UserTypeOrganization,
|
||||
PageSize: setting.UI.ExplorePagingNum,
|
||||
Private: ctx.User != nil,
|
||||
OwnerID: ownerID,
|
||||
}, tplExploreOrganizations)
|
||||
}
|
||||
|
||||
@@ -304,7 +301,7 @@ func ExploreCode(ctx *context.Context) {
|
||||
|
||||
// guest user or non-admin user
|
||||
if ctx.User == nil || !isAdmin {
|
||||
repoIDs, err = models.FindUserAccessibleRepoIDs(userID)
|
||||
repoIDs, err = models.FindUserAccessibleRepoIDs(ctx.User)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchResults", err)
|
||||
return
|
||||
|
||||
@@ -80,8 +80,7 @@ func Home(ctx *context.Context) {
|
||||
OwnerID: org.ID,
|
||||
OrderBy: orderBy,
|
||||
Private: ctx.IsSigned,
|
||||
UserIsAdmin: ctx.IsUserSiteAdmin(),
|
||||
UserID: ctx.Data["SignedUserID"].(int64),
|
||||
Actor: ctx.User,
|
||||
Page: page,
|
||||
IsProfile: true,
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
|
||||
@@ -144,6 +144,7 @@ func Dashboard(ctx *context.Context) {
|
||||
|
||||
retrieveFeeds(ctx, models.GetFeedsOptions{
|
||||
RequestedUser: ctxUser,
|
||||
Actor: ctx.User,
|
||||
IncludePrivate: true,
|
||||
OnlyPerformedBy: false,
|
||||
IncludeDeleted: false,
|
||||
|
||||
@@ -161,6 +161,7 @@ func Profile(ctx *context.Context) {
|
||||
switch tab {
|
||||
case "activity":
|
||||
retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
|
||||
Actor: ctx.User,
|
||||
IncludePrivate: showPrivate,
|
||||
OnlyPerformedBy: true,
|
||||
IncludeDeleted: false,
|
||||
@@ -171,11 +172,10 @@ func Profile(ctx *context.Context) {
|
||||
case "stars":
|
||||
ctx.Data["PageIsProfileStarList"] = true
|
||||
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
|
||||
Actor: ctx.User,
|
||||
Keyword: keyword,
|
||||
OrderBy: orderBy,
|
||||
Private: ctx.IsSigned,
|
||||
UserIsAdmin: ctx.IsUserSiteAdmin(),
|
||||
UserID: ctx.Data["SignedUserID"].(int64),
|
||||
Page: page,
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
StarredByID: ctxUser.ID,
|
||||
@@ -191,12 +191,11 @@ func Profile(ctx *context.Context) {
|
||||
total = int(count)
|
||||
default:
|
||||
repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
|
||||
Actor: ctx.User,
|
||||
Keyword: keyword,
|
||||
OwnerID: ctxUser.ID,
|
||||
OrderBy: orderBy,
|
||||
Private: ctx.IsSigned,
|
||||
UserIsAdmin: ctx.IsUserSiteAdmin(),
|
||||
UserID: ctx.Data["SignedUserID"].(int64),
|
||||
Page: page,
|
||||
IsProfile: true,
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
|
||||
Reference in New Issue
Block a user