Refactor Visibletype Orgs (#382)

refactor VisibleType

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/382
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-07-16 02:17:33 +00:00 committed by techknowlogick
parent 1026b1014c
commit b04ccca570
3 changed files with 28 additions and 44 deletions

View file

@ -22,8 +22,7 @@ func TestAdminOrg(t *testing.T) {
UserName: orgName,
FullName: orgName + " FullName",
Description: "test adminCreateOrg",
// enum: public,limited,private
Visibility: "public",
Visibility: VisibleTypePublic,
})
assert.NoError(t, err)
assert.NotEmpty(t, newOrg)

View file

@ -23,6 +23,20 @@ type Organization struct {
Visibility string `json:"visibility"`
}
// VisibleType defines the visibility
type VisibleType string
const (
// VisibleTypePublic Visible for everyone
VisibleTypePublic VisibleType = "public"
// VisibleTypeLimited Visible for every connected user
VisibleTypeLimited VisibleType = "limited"
// VisibleTypePrivate Visible only for organization's members
VisibleTypePrivate VisibleType = "private"
)
// ListOrgsOptions options for listing organizations
type ListOrgsOptions struct {
ListOptions
@ -50,18 +64,17 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
// CreateOrgOption options for creating an organization
type CreateOrgOption struct {
UserName string `json:"username"`
FullName string `json:"full_name"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
// possible values are `public` (default), `limited` or `private`
Visibility string `json:"visibility"`
UserName string `json:"username"`
FullName string `json:"full_name"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
Visibility VisibleType `json:"visibility"`
}
// checkVisibilityOpt check if mode exist
func checkVisibilityOpt(v string) bool {
return v == "public" || v == "limited" || v == "private"
func checkVisibilityOpt(v VisibleType) bool {
return v == VisibleTypePublic || v == VisibleTypeLimited || v == VisibleTypePrivate
}
// Validate the CreateOrgOption struct
@ -90,12 +103,11 @@ func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) {
// EditOrgOption options for editing an organization
type EditOrgOption struct {
FullName string `json:"full_name"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
// possible values are `public`, `limited` or `private`
Visibility string `json:"visibility"`
FullName string `json:"full_name"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
Visibility VisibleType `json:"visibility"`
}
// Validate the EditOrgOption struct

View file

@ -1,27 +0,0 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
// VisibleType defines the visibility (Organization only)
type VisibleType int
const (
// VisibleTypePublic Visible for everyone
VisibleTypePublic VisibleType = iota
// VisibleTypeLimited Visible for every connected user
VisibleTypeLimited
// VisibleTypePrivate Visible only for organization's members
VisibleTypePrivate
)
// ExtractKeysFromMapString provides a slice of keys from map
func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
for k := range in {
keys = append(keys, k)
}
return
}