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.

38 lines
793 B

  1. // Copyright 2014 The Gogs 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. package models
  5. import (
  6. "strings"
  7. "time"
  8. )
  9. const (
  10. AU_READABLE = iota + 1
  11. AU_WRITABLE
  12. )
  13. type Access struct {
  14. Id int64
  15. UserName string `xorm:"unique(s)"`
  16. RepoName string `xorm:"unique(s)"`
  17. Mode int `xorm:"unique(s)"`
  18. Created time.Time `xorm:"created"`
  19. }
  20. func AddAccess(access *Access) error {
  21. _, err := orm.Insert(access)
  22. return err
  23. }
  24. // if one user can read or write one repository
  25. func HasAccess(userName, repoName string, mode int) (bool, error) {
  26. return orm.Get(&Access{
  27. Id: 0,
  28. UserName: strings.ToLower(userName),
  29. RepoName: strings.ToLower(repoName),
  30. Mode: mode,
  31. })
  32. }