mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(team,repo,org,wiki,auth): detect a kept admin permission, validate topics up front, page public members, name disabled wikis, treat auth switch's account as --user
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
12 files changed
+289
-64
No files matched your search
+32
-11
@@ -133,8 +133,34 @@ func (s Wiki) ListPage(ctx context.Context, limit, page int) (Page[WikiPage], er
|
||||
return Page[WikiPage]{Items: items, More: page*limit < len(all), Total: len(all), Counted: true}, err
|
||||
}
|
||||
|
||||
// disabled explains a 404 from the wiki API. Gitea answers a bare 404 when the wiki is disabled or
|
||||
// the repository is missing, which says nothing about the page itself. It returns nil for any other
|
||||
// error, and the repository lookup's error when the repository cannot be read.
|
||||
func (s Wiki) disabled(ctx context.Context, err error) error {
|
||||
if !IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
repository, checkErr := (Repositories{Client: s.Client}).get(ctx, s.Repository)
|
||||
if checkErr != nil {
|
||||
return checkErr
|
||||
}
|
||||
if !repository.HasWiki {
|
||||
return fmt.Errorf("the wiki of %s is disabled; turn it on with: tea repo edit --enable-wiki -R %s", s.Repository, s.Repository)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// View retrieves and decodes a wiki page.
|
||||
func (s Wiki) View(ctx context.Context, name string) (WikiPage, error) {
|
||||
item, err := s.lookup(ctx, name)
|
||||
if err := s.disabled(ctx, err); err != nil {
|
||||
return WikiPage{}, err
|
||||
}
|
||||
return item, err
|
||||
}
|
||||
|
||||
// lookup is View without the check for a disabled wiki.
|
||||
func (s Wiki) lookup(ctx context.Context, name string) (WikiPage, error) {
|
||||
item, err := s.page(ctx, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.WikiPage, *gitea.Response, error) {
|
||||
return c.Wiki.GetPage(ctx, owner, repo, name)
|
||||
})
|
||||
@@ -150,16 +176,8 @@ func (s Wiki) Create(ctx context.Context, opts WikiOptions) (WikiPage, error) {
|
||||
item, err := s.page(ctx, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.WikiPage, *gitea.Response, error) {
|
||||
return c.Wiki.CreatePage(ctx, owner, repo, wikiOptions(opts))
|
||||
})
|
||||
if IsNotFound(err) {
|
||||
// Gitea answers a bare 404 when the wiki is disabled or the repository is missing, which
|
||||
// says nothing about the page being created.
|
||||
repository, checkErr := (Repositories{Client: s.Client}).get(ctx, s.Repository)
|
||||
if checkErr != nil {
|
||||
return WikiPage{}, checkErr
|
||||
}
|
||||
if !repository.HasWiki {
|
||||
return WikiPage{}, fmt.Errorf("the wiki of %s is disabled; turn it on with: tea repo edit --enable-wiki -R %s", s.Repository, s.Repository)
|
||||
}
|
||||
if err := s.disabled(ctx, err); err != nil {
|
||||
return WikiPage{}, err
|
||||
}
|
||||
return item, Classify(err, "wiki page", strconv.Quote(opts.Title), s.Repository)
|
||||
}
|
||||
@@ -177,7 +195,7 @@ func (s Wiki) Edit(ctx context.Context, name string, opts WikiOptions) (WikiPage
|
||||
opts.Title = current.Title
|
||||
}
|
||||
if renamed {
|
||||
existing, err := s.View(ctx, opts.Title)
|
||||
existing, err := s.lookup(ctx, opts.Title)
|
||||
if err == nil && existing.Title != current.Title {
|
||||
return WikiPage{}, false, &ConflictError{Reason: ReasonExists, Kind: "wiki page", Key: strconv.Quote(opts.Title), Scope: s.Repository}
|
||||
}
|
||||
@@ -196,6 +214,9 @@ func (s Wiki) Delete(ctx context.Context, name string) error {
|
||||
err := repoDo(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Response, error) {
|
||||
return c.Wiki.DeletePage(ctx, owner, repo, name)
|
||||
})
|
||||
if err := s.disabled(ctx, err); err != nil {
|
||||
return err
|
||||
}
|
||||
return Classify(err, "wiki page", strconv.Quote(name), s.Repository)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user