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:
parent
1026b1014c
commit
b04ccca570
3 changed files with 28 additions and 44 deletions
|
@ -22,8 +22,7 @@ func TestAdminOrg(t *testing.T) {
|
||||||
UserName: orgName,
|
UserName: orgName,
|
||||||
FullName: orgName + " FullName",
|
FullName: orgName + " FullName",
|
||||||
Description: "test adminCreateOrg",
|
Description: "test adminCreateOrg",
|
||||||
// enum: public,limited,private
|
Visibility: VisibleTypePublic,
|
||||||
Visibility: "public",
|
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, newOrg)
|
assert.NotEmpty(t, newOrg)
|
||||||
|
|
42
gitea/org.go
42
gitea/org.go
|
@ -23,6 +23,20 @@ type Organization struct {
|
||||||
Visibility string `json:"visibility"`
|
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
|
// ListOrgsOptions options for listing organizations
|
||||||
type ListOrgsOptions struct {
|
type ListOrgsOptions struct {
|
||||||
ListOptions
|
ListOptions
|
||||||
|
@ -50,18 +64,17 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||||
|
|
||||||
// CreateOrgOption options for creating an organization
|
// CreateOrgOption options for creating an organization
|
||||||
type CreateOrgOption struct {
|
type CreateOrgOption struct {
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Website string `json:"website"`
|
Website string `json:"website"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
// possible values are `public` (default), `limited` or `private`
|
Visibility VisibleType `json:"visibility"`
|
||||||
Visibility string `json:"visibility"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkVisibilityOpt check if mode exist
|
// checkVisibilityOpt check if mode exist
|
||||||
func checkVisibilityOpt(v string) bool {
|
func checkVisibilityOpt(v VisibleType) bool {
|
||||||
return v == "public" || v == "limited" || v == "private"
|
return v == VisibleTypePublic || v == VisibleTypeLimited || v == VisibleTypePrivate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the CreateOrgOption struct
|
// Validate the CreateOrgOption struct
|
||||||
|
@ -90,12 +103,11 @@ func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) {
|
||||||
|
|
||||||
// EditOrgOption options for editing an organization
|
// EditOrgOption options for editing an organization
|
||||||
type EditOrgOption struct {
|
type EditOrgOption struct {
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Website string `json:"website"`
|
Website string `json:"website"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
// possible values are `public`, `limited` or `private`
|
Visibility VisibleType `json:"visibility"`
|
||||||
Visibility string `json:"visibility"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the EditOrgOption struct
|
// Validate the EditOrgOption struct
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in a new issue