diff --git a/rest/feature.go b/rest/feature.go new file mode 100644 index 0000000..661ac17 --- /dev/null +++ b/rest/feature.go @@ -0,0 +1,15 @@ +package rest + +//这里是用来定义系统中接口的访问级别的,不同角色将对不同feature具有访问权限。 +const ( + //公共接口,所有人均可访问。 + FEATURE_PUBLIC = "FEATURE_TYPE_PUBLIC" + //管理用户,只有超级管理员可以访问。 + FEATURE_USER_MANAGE = "FEATURE_USER_MANAGE" + //管理文件,只有超级管理员可以访问。 + FEATURE_MATTER_MANAGE = "FEATURE_MATTER_MANAGE" + //查看自己资料,普通用户和超级管理员可以访问。 + FEATURE_USER_MINE = "FEATURE_USER_MINE" + //其他,超级管理员可以访问。 + FEATURE_OTHER = "FEATURE_OTHER" +) diff --git a/rest/install.go b/rest/install.go index 3556838..e62c210 100644 --- a/rest/install.go +++ b/rest/install.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/jinzhu/gorm" "github.com/nu7hatch/gouuid" - "regexp" "time" ) diff --git a/rest/user_model.go b/rest/user_model.go index aa0f725..77befda 100644 --- a/rest/user_model.go +++ b/rest/user_model.go @@ -61,3 +61,14 @@ func GetRole(roleString string) string { return USER_ROLE_USER } } + +//检查某种用户角色对于某个功能点是否有访问权限。 +func (this *User) HasPermission(feature string) bool { + if this.Role == USER_ROLE_ADMINISTRATOR { + return true + } else if this.Role == USER_ROLE_USER { + return feature == FEATURE_PUBLIC || feature == FEATURE_USER_MINE + } else { + return feature == FEATURE_PUBLIC + } +}