diff options
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/admin/org.go | 4 | ||||
-rw-r--r-- | routers/api/v1/org/hook.go | 4 | ||||
-rw-r--r-- | routers/api/v1/org/label.go | 8 | ||||
-rw-r--r-- | routers/api/v1/org/org.go | 15 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/fork.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/transfer.go | 4 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/utils/hook.go | 4 |
11 files changed, 27 insertions, 26 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index 5da87fa7df..2633865d2c 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -54,7 +54,7 @@ func CreateOrg(ctx *context.APIContext) { visibility = api.VisibilityModes[form.Visibility] } - org := &models.User{ + org := &models.Organization{ Name: form.UserName, FullName: form.FullName, Description: form.Description, @@ -117,7 +117,7 @@ func GetAllOrgs(ctx *context.APIContext) { } orgs := make([]*api.Organization, len(users)) for i := range users { - orgs[i] = convert.ToOrganization(users[i]) + orgs[i] = convert.ToOrganization(models.OrgFromUser(users[i])) } ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) diff --git a/routers/api/v1/org/hook.go b/routers/api/v1/org/hook.go index 6c81616170..b9d1fa2f67 100644 --- a/routers/api/v1/org/hook.go +++ b/routers/api/v1/org/hook.go @@ -59,7 +59,7 @@ func ListHooks(ctx *context.APIContext) { hooks := make([]*api.Hook, len(orgHooks)) for i, hook := range orgHooks { - hooks[i] = convert.ToHook(ctx.Org.Organization.HomeLink(), hook) + hooks[i] = convert.ToHook(ctx.Org.Organization.AsUser().HomeLink(), hook) } ctx.SetTotalCountHeader(count) @@ -95,7 +95,7 @@ func GetHook(ctx *context.APIContext) { if err != nil { return } - ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook)) + ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), hook)) } // CreateHook create a hook for an organization diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index b375284189..7d4c12d364 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -56,7 +56,7 @@ func ListLabels(ctx *context.APIContext) { } ctx.SetTotalCountHeader(count) - ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization)) + ctx.JSON(http.StatusOK, convert.ToLabelList(labels, nil, ctx.Org.Organization.AsUser())) } // CreateLabel create a label for a repository @@ -104,7 +104,7 @@ func CreateLabel(ctx *context.APIContext) { return } - ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization)) + ctx.JSON(http.StatusCreated, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser())) } // GetLabel get label by organization and label id @@ -149,7 +149,7 @@ func GetLabel(ctx *context.APIContext) { return } - ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization)) + ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser())) } // EditLabel modify a label for an Organization @@ -214,7 +214,7 @@ func EditLabel(ctx *context.APIContext) { return } - ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization)) + ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser())) } // DeleteLabel delete a label for an organization diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index e82e8552e0..bbf127f891 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -31,7 +31,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User) { } maxResults := len(orgs) - orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.User) + orgs, _ = util.PaginateSlice(orgs, listOptions.Page, listOptions.PageSize).([]*models.Organization) apiOrgs := make([]*api.Organization, len(orgs)) for i := range orgs { @@ -141,7 +141,8 @@ func GetUserOrgsPermissions(ctx *context.APIContext) { return } - authorizeLevel, err := o.GetOrgUserMaxAuthorizeLevel(u.ID) + org := models.OrgFromUser(o) + authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(u.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err) return @@ -160,7 +161,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) { op.IsOwner = true } - op.CanCreateRepository, err = o.CanCreateOrgRepo(u.ID) + op.CanCreateRepository, err = org.CanCreateOrgRepo(u.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err) return @@ -212,7 +213,7 @@ func GetAll(ctx *context.APIContext) { } orgs := make([]*api.Organization, len(publicOrgs)) for i := range publicOrgs { - orgs[i] = convert.ToOrganization(publicOrgs[i]) + orgs[i] = convert.ToOrganization(models.OrgFromUser(publicOrgs[i])) } ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) @@ -252,7 +253,7 @@ func Create(ctx *context.APIContext) { visibility = api.VisibilityModes[form.Visibility] } - org := &models.User{ + org := &models.Organization{ Name: form.UserName, FullName: form.FullName, Description: form.Description, @@ -295,7 +296,7 @@ func Get(ctx *context.APIContext) { // "200": // "$ref": "#/responses/Organization" - if !models.HasOrgOrUserVisible(ctx.Org.Organization, ctx.User) { + if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.User) { ctx.NotFound("HasOrgOrUserVisible", nil) return } @@ -337,7 +338,7 @@ func Edit(ctx *context.APIContext) { if form.RepoAdminChangeTeamAccess != nil { org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess } - if err := models.UpdateUserCols(org, + if err := models.UpdateUserCols(org.AsUser(), "full_name", "description", "website", "location", "visibility", "repo_admin_change_team_access", ); err != nil { diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 0dc1b68aee..e78e487895 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -102,7 +102,7 @@ func ListUserTeams(ctx *context.APIContext) { for i := range teams { apiOrg, ok := cache[teams[i].OrgID] if !ok { - org, err := models.GetUserByID(teams[i].OrgID) + org, err := models.GetOrgByID(teams[i].OrgID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserByID", err) return diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index b3504faad9..45d3c815a7 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -120,7 +120,7 @@ func CreateFork(ctx *context.APIContext) { ctx.Error(http.StatusForbidden, "isMemberNot", fmt.Sprintf("User is no Member of Organisation '%s'", org.Name)) return } - forker = org + forker = org.AsUser() } fork, err := repo_service.ForkRepository(ctx.User, forker, models.ForkRepoOptions{ diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 00390dfb5f..1880a88367 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -86,7 +86,7 @@ func Migrate(ctx *context.APIContext) { if repoOwner.IsOrganization() { // Check ownership of organization. - isOwner, err := repoOwner.IsOwnedBy(ctx.User.ID) + isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.User.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 22f9da614d..872ce22871 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -393,7 +393,7 @@ func Generate(ctx *context.APIContext) { } if !ctx.User.IsAdmin { - canCreate, err := ctxUser.CanCreateOrgRepo(ctx.User.ID) + canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID) if err != nil { ctx.ServerError("CanCreateOrgRepo", err) return @@ -489,7 +489,7 @@ func CreateOrgRepo(ctx *context.APIContext) { return } - if !models.HasOrgOrUserVisible(org, ctx.User) { + if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) { ctx.NotFound("HasOrgOrUserVisible", nil) return } @@ -504,7 +504,7 @@ func CreateOrgRepo(ctx *context.APIContext) { return } } - CreateUserRepo(ctx, org, *opt) + CreateUserRepo(ctx, org.AsUser(), *opt) } // Get one repository diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index c13a2e4857..f16e2bb081 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -64,7 +64,7 @@ func Transfer(ctx *context.APIContext) { } if newOwner.Type == models.UserTypeOrganization { - if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !newOwner.HasMemberWithUserID(ctx.User.ID) { + if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) { // The user shouldn't know about this organization ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found") return @@ -78,7 +78,7 @@ func Transfer(ctx *context.APIContext) { return } - org := convert.ToOrganization(newOwner) + org := convert.ToOrganization(models.OrgFromUser(newOwner)) for _, tID := range *opts.TeamIDs { team, err := models.GetTeamByID(tID) if err != nil { diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 5116c17ab2..3c9a17a0be 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -157,5 +157,5 @@ func ListOrgRepos(ctx *context.APIContext) { // "200": // "$ref": "#/responses/RepositoryList" - listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned) + listUserRepos(ctx, ctx.Org.Organization.AsUser(), ctx.IsSigned) } diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index aef9b8f4ce..1f0a35ce22 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -75,7 +75,7 @@ func AddOrgHook(ctx *context.APIContext, form *api.CreateHookOption) { org := ctx.Org.Organization hook, ok := addHook(ctx, form, org.ID, 0) if ok { - ctx.JSON(http.StatusCreated, convert.ToHook(org.HomeLink(), hook)) + ctx.JSON(http.StatusCreated, convert.ToHook(org.AsUser().HomeLink(), hook)) } } @@ -185,7 +185,7 @@ func EditOrgHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64 if err != nil { return } - ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), updated)) + ctx.JSON(http.StatusOK, convert.ToHook(org.AsUser().HomeLink(), updated)) } // EditRepoHook edit webhook `w` according to `form`. Writes to `ctx` accordingly |