36 lines
746 B
Go
36 lines
746 B
Go
package calendar
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"kumoly.io/kumoly/app/auth"
|
|
"kumoly.io/kumoly/app/errors"
|
|
)
|
|
|
|
func HasCalAccess(c *gin.Context, cal *Calendar, cid string) error {
|
|
err := db.First(cal, "id = ?", cid).Error
|
|
if err != nil {
|
|
return errors.NewError(404, err)
|
|
}
|
|
if cal.GroupName == "" {
|
|
return nil
|
|
}
|
|
if !auth.ACHas(c, auth.ADMIN, auth.SYSTEM, cal.GroupName) {
|
|
return errors.ErrorForbidden
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func HasEventAccess(c *gin.Context, e *Event, cid string) error {
|
|
err := db.First(e, "id = ?", cid).Error
|
|
if err != nil {
|
|
return errors.NewError(404, err)
|
|
}
|
|
if e.GroupName == "" {
|
|
return nil
|
|
}
|
|
if !auth.ACHas(c, auth.ADMIN, auth.SYSTEM, e.GroupName) {
|
|
return errors.ErrorForbidden
|
|
}
|
|
return nil
|
|
}
|