// Copyright 2020 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 models

import "code.gitea.io/gitea/modules/log"

// GetUserDataSetPermission returns the user permissions to the data_set
func GetUserDataSetPermission(dataSet *Dataset, user *User) (isPermit bool, err error) {
	isPermit = false

	if user != nil {
		switch dataSet.Status {
		case DatasetStatusDeleted:
			log.Error("the data_set has been deleted")
		case DatasetStatusPrivate:
			if !user.IsAdmin && user.ID != dataSet.UserID {
				log.Error("the user is not admin nor the owner of the data_set")
			}
			isPermit = true

		case DatasetStatusPublic:
			isPermit = true
		default:
			log.Error("the status of data_set is wrong")
		}
	}

	return isPermit, nil

}
