1// Copyright 2019 The Gitea Authors. All rights reserved. 2// Use of this source code is governed by a MIT-style 3// license that can be found in the LICENSE file. 4 5package structs 6 7// VisibleType defines the visibility (Organization only) 8type VisibleType int 9 10const ( 11 // VisibleTypePublic Visible for everyone 12 VisibleTypePublic VisibleType = iota 13 14 // VisibleTypeLimited Visible for every connected user 15 VisibleTypeLimited 16 17 // VisibleTypePrivate Visible only for organization's members 18 VisibleTypePrivate 19) 20 21// VisibilityModes is a map of org Visibility types 22var VisibilityModes = map[string]VisibleType{ 23 "public": VisibleTypePublic, 24 "limited": VisibleTypeLimited, 25 "private": VisibleTypePrivate, 26} 27 28// IsPublic returns true if VisibleType is public 29func (vt VisibleType) IsPublic() bool { 30 return vt == VisibleTypePublic 31} 32 33// IsLimited returns true if VisibleType is limited 34func (vt VisibleType) IsLimited() bool { 35 return vt == VisibleTypeLimited 36} 37 38// IsPrivate returns true if VisibleType is private 39func (vt VisibleType) IsPrivate() bool { 40 return vt == VisibleTypePrivate 41} 42 43// VisibilityString provides the mode string of the visibility type (public, limited, private) 44func (vt VisibleType) String() string { 45 for k, v := range VisibilityModes { 46 if vt == v { 47 return k 48 } 49 } 50 return "" 51} 52 53// ExtractKeysFromMapString provides a slice of keys from map 54func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { 55 for k := range in { 56 keys = append(keys, k) 57 } 58 return 59} 60