You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

visible_type.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package structs
  4. // VisibleType defines the visibility of user and org
  5. type VisibleType int
  6. const (
  7. // VisibleTypePublic Visible for everyone
  8. VisibleTypePublic VisibleType = iota
  9. // VisibleTypeLimited Visible for every connected user
  10. VisibleTypeLimited
  11. // VisibleTypePrivate Visible only for self or admin user
  12. VisibleTypePrivate
  13. )
  14. // VisibilityModes is a map of Visibility types
  15. var VisibilityModes = map[string]VisibleType{
  16. "public": VisibleTypePublic,
  17. "limited": VisibleTypeLimited,
  18. "private": VisibleTypePrivate,
  19. }
  20. // IsPublic returns true if VisibleType is public
  21. func (vt VisibleType) IsPublic() bool {
  22. return vt == VisibleTypePublic
  23. }
  24. // IsLimited returns true if VisibleType is limited
  25. func (vt VisibleType) IsLimited() bool {
  26. return vt == VisibleTypeLimited
  27. }
  28. // IsPrivate returns true if VisibleType is private
  29. func (vt VisibleType) IsPrivate() bool {
  30. return vt == VisibleTypePrivate
  31. }
  32. // VisibilityString provides the mode string of the visibility type (public, limited, private)
  33. func (vt VisibleType) String() string {
  34. for k, v := range VisibilityModes {
  35. if vt == v {
  36. return k
  37. }
  38. }
  39. return ""
  40. }
  41. // ExtractKeysFromMapString provides a slice of keys from map
  42. func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
  43. for k := range in {
  44. keys = append(keys, k)
  45. }
  46. return keys
  47. }