mv get roles

Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
runzexia
2019-04-24 11:04:06 +08:00
committed by zryfish
parent 5a6f51d775
commit 68809bcc38
6 changed files with 70 additions and 221 deletions

View File

@@ -35,7 +35,6 @@ import (
"kubesphere.io/kubesphere/pkg/models/resources"
"kubesphere.io/kubesphere/pkg/params"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/kubesphere"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sort"
@@ -48,17 +47,6 @@ const (
NamespaceViewerRoleBindName = "viewer"
)
func GetUserDevopsSimpleRules(username, projectId string) ([]models.SimpleRule, error) {
role, err := kubesphere.Client().GetUserDevopsRole(username, projectId)
if err != nil {
glog.Errorln("get user devops role", username, projectId, err)
return nil, err
}
return GetDevopsRoleSimpleRules(role), nil
}
func GetDevopsRoleSimpleRules(role string) []models.SimpleRule {
var rules []models.SimpleRule

View File

@@ -484,3 +484,70 @@ func CreateDevopsProject(username string, workspace string, req *devops.DevOpsPr
}
return project, nil, http.StatusOK
}
func GetUserDevopsSimpleRules(username, projectId string) ([]models.SimpleRule, error, int) {
err := CheckProjectUserInRole(username, projectId, AllRoleSlice)
if err != nil {
glog.Errorf("%+v", err)
return nil, err, http.StatusForbidden
}
dbconn := devops_mysql.OpenDatabase()
memberships := &devops.DevOpsProjectMembership{}
err = dbconn.Select(devops.DevOpsProjectMembershipColumns...).
From(devops.DevOpsProjectMembershipTableName).
Where(db.And(
db.Eq(devops.DevOpsProjectMembershipProjectIdColumn, projectId),
db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username))).
LoadOne(&memberships)
if err != nil {
glog.Errorf("%+v", err)
return nil, err, http.StatusInternalServerError
}
return GetDevopsRoleSimpleRules(memberships.Role), nil, http.StatusOK
}
func GetDevopsRoleSimpleRules(role string) []models.SimpleRule {
var rules []models.SimpleRule
switch role {
case "developer":
rules = []models.SimpleRule{
{Name: "pipelines", Actions: []string{"view", "trigger"}},
{Name: "roles", Actions: []string{"view"}},
{Name: "members", Actions: []string{"view"}},
{Name: "devops", Actions: []string{"view"}},
}
break
case "owner":
rules = []models.SimpleRule{
{Name: "pipelines", Actions: []string{"create", "edit", "view", "delete", "trigger"}},
{Name: "roles", Actions: []string{"view"}},
{Name: "members", Actions: []string{"create", "edit", "view", "delete"}},
{Name: "credentials", Actions: []string{"create", "edit", "view", "delete"}},
{Name: "devops", Actions: []string{"edit", "view", "delete"}},
}
break
case "maintainer":
rules = []models.SimpleRule{
{Name: "pipelines", Actions: []string{"create", "edit", "view", "delete", "trigger"}},
{Name: "roles", Actions: []string{"view"}},
{Name: "members", Actions: []string{"view"}},
{Name: "credentials", Actions: []string{"create", "edit", "view", "delete"}},
{Name: "devops", Actions: []string{"view"}},
}
break
case "reporter":
fallthrough
default:
rules = []models.SimpleRule{
{Name: "pipelines", Actions: []string{"view"}},
{Name: "roles", Actions: []string{"view"}},
{Name: "members", Actions: []string{"view"}},
{Name: "devops", Actions: []string{"view"}},
}
break
}
return rules
}

View File

@@ -36,21 +36,6 @@ type Workspace struct {
DevopsProjects []string `json:"devops_projects"`
}
type WorkspaceDPBinding struct {
Workspace string `gorm:"primary_key"`
DevOpsProject string `gorm:"primary_key"`
}
type DevopsProject struct {
ProjectId string `json:"project_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Creator string `json:"creator"`
CreateTime *time.Time `json:"create_time,omitempty"`
Status *string `json:"status"`
Visibility *string `json:"visibility,omitempty"`
}
type Action struct {
Name string `json:"name"`
Rules []v1.PolicyRule `json:"rules"`