mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-29 03:51:54 +08:00
fix: code autogen issues
This commit is contained in:
@@ -291,9 +291,11 @@ gen-swagger: gen-swagger-check
|
||||
$(ROOT_DIR)/scripts/codegen.py swagger-code
|
||||
$(ROOT_DIR)/scripts/codegen.py swagger-yaml
|
||||
|
||||
swagger-serve: gen-model-api gen-swagger
|
||||
swagger-serve-only:
|
||||
$(ROOT_DIR)/scripts/codegen.py swagger-serve
|
||||
|
||||
swagger-serve: gen-model-api gen-swagger swagger-serve-only
|
||||
|
||||
swagger-site: gen-model-api gen-swagger
|
||||
$(ROOT_DIR)/scripts/codegen.py swagger-site
|
||||
|
||||
|
||||
@@ -224,4 +224,29 @@ func init() {
|
||||
printObject(sp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type GroupAddUsersOptions struct {
|
||||
GROUP string `help:"group Id or Name" json:"-"`
|
||||
USER []string `help:"list of user id or name" json:"user"`
|
||||
}
|
||||
R(&GroupAddUsersOptions{}, "group-add-users", "Add users into group",
|
||||
func(s *mcclient.ClientSession, args *GroupAddUsersOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
result, err := modules.Groups.PerformAction(s, args.GROUP, "add-users", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
R(&GroupAddUsersOptions{}, "group-remove-users", "Add users into group",
|
||||
func(s *mcclient.ClientSession, args *GroupAddUsersOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
result, err := modules.Groups.PerformAction(s, args.GROUP, "remove-users", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ type CloudaccountUpdateInput struct {
|
||||
}
|
||||
|
||||
type CloudaccountPerformPublicInput struct {
|
||||
apis.PerformPublicInput
|
||||
apis.PerformPublicDomainInput
|
||||
|
||||
// 共享模式,可能值为provider_domain, system
|
||||
// example: provider_domain
|
||||
|
||||
@@ -194,8 +194,8 @@ type EndpointListInput struct {
|
||||
}
|
||||
|
||||
type SJoinProjectsInput struct {
|
||||
Projects []string
|
||||
Roles []string
|
||||
Projects []string `json:"projects"`
|
||||
Roles []string `json:"roles"`
|
||||
}
|
||||
|
||||
func (input SJoinProjectsInput) Validate() error {
|
||||
@@ -209,11 +209,12 @@ func (input SJoinProjectsInput) Validate() error {
|
||||
}
|
||||
|
||||
type SProjectRole struct {
|
||||
Project string
|
||||
Role string
|
||||
Project string `json:"project"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type SLeaveProjectsInput struct {
|
||||
ProjectRoles []SProjectRole
|
||||
ProjectRoles []SProjectRole `json:"project_roles"`
|
||||
}
|
||||
|
||||
func (input SLeaveProjectsInput) Validate() error {
|
||||
@@ -451,3 +452,13 @@ type RoleCreateInput struct {
|
||||
|
||||
apis.SharableResourceBaseCreateInput
|
||||
}
|
||||
|
||||
type PerformGroupAddUsersInput struct {
|
||||
// 带添加用户列表(ID或名称)
|
||||
User []string `json:"user"`
|
||||
}
|
||||
|
||||
type PerformGroupRemoveUsersInput struct {
|
||||
// 带删除用户列表(ID或名称)
|
||||
User []string `json:"user"`
|
||||
}
|
||||
|
||||
+34
-4
@@ -180,18 +180,22 @@ type GetDetailsStatusOutput struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type PerformPublicInput struct {
|
||||
type PerformPublicDomainInput struct {
|
||||
// 共享项目资源的共享范围,可能的值为:project, domain和system
|
||||
// pattern: project|domain|system
|
||||
Scope string `json:"scope"`
|
||||
|
||||
// 如果共享范围为项目,则在此列表中指定共享的目标项目
|
||||
SharedProjects []string `json:"shared_projects"`
|
||||
|
||||
// 如果共享范围为域,则在此列表中指定共享的目标域
|
||||
SharedDomains []string `json:"shared_domains"`
|
||||
}
|
||||
|
||||
type PerformPublicProjectInput struct {
|
||||
PerformPublicDomainInput
|
||||
|
||||
// 如果共享范围为项目,则在此列表中指定共享的目标项目
|
||||
SharedProjects []string `json:"shared_projects"`
|
||||
}
|
||||
|
||||
type PerformPrivateInput struct {
|
||||
}
|
||||
|
||||
@@ -249,3 +253,29 @@ type OpsLogCreateInput struct {
|
||||
OwnerDomainId string `json:"owner_domain_id"`
|
||||
OwnerProjectId string `json:"owner_tenant_id"`
|
||||
}
|
||||
|
||||
// 设置资源的标签(元数据)输入
|
||||
type PerformMetadataInput map[string]string
|
||||
|
||||
// 设置资源的用户标签(元数据)输入
|
||||
type PerformUserMetadataInput map[string]string
|
||||
|
||||
// 全量替换资源的用户标签(元数据)输入
|
||||
type PerformSetUserMetadataInput map[string]string
|
||||
|
||||
// 获取资源的元数据输入
|
||||
type GetMetadataInput struct {
|
||||
// 指定需要获取的所有标签的KEY列表,如果列表为空,则获取全部标签
|
||||
// 标签分为
|
||||
//
|
||||
// | 类型 | 说明 |
|
||||
// |----------|---------------------------------------------|
|
||||
// | 系统标签 | 平台定义的标签 |
|
||||
// | 用户标签 | key以user:为前缀,用户自定义标签 |
|
||||
// | 外部标签 | key以ext:为前缀,为从其他平台同步过来的标签 |
|
||||
//
|
||||
Field []string `json:"field"`
|
||||
}
|
||||
|
||||
// 获取资源标签(元数据)输出
|
||||
type GetMetadataOutput map[string]string
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ type ModelBaseDetails struct {
|
||||
// example: true
|
||||
CanUpdate bool `json:"can_update"`
|
||||
|
||||
// 资源不能删除的原因
|
||||
// 资源不能更新的原因
|
||||
UpdateFailReason string `json:"update_fail_reason"`
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ func (self *SEnabledStatusDomainLevelResourceBase) AllowPerformEnable(ctx contex
|
||||
return IsDomainAllowPerform(userCred, self, "enable")
|
||||
}
|
||||
|
||||
// 启用资源
|
||||
func (self *SEnabledStatusDomainLevelResourceBase) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, true)
|
||||
if err != nil {
|
||||
@@ -59,6 +60,7 @@ func (self *SEnabledStatusDomainLevelResourceBase) AllowPerformDisable(ctx conte
|
||||
return IsDomainAllowPerform(userCred, self, "disable")
|
||||
}
|
||||
|
||||
// 禁用资源
|
||||
func (self *SEnabledStatusDomainLevelResourceBase) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,7 @@ func (self *SEnabledStatusInfrasResourceBase) AllowPerformEnable(ctx context.Con
|
||||
return IsDomainAllowPerform(userCred, self, "enable")
|
||||
}
|
||||
|
||||
// 启用资源
|
||||
func (self *SEnabledStatusInfrasResourceBase) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, true)
|
||||
if err != nil {
|
||||
@@ -59,6 +60,7 @@ func (self *SEnabledStatusInfrasResourceBase) AllowPerformDisable(ctx context.Co
|
||||
return IsDomainAllowPerform(userCred, self, "disable")
|
||||
}
|
||||
|
||||
// 禁用资源
|
||||
func (self *SEnabledStatusInfrasResourceBase) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,7 @@ func (self *SEnabledStatusStandaloneResourceBase) AllowPerformEnable(ctx context
|
||||
return IsAdminAllowPerform(userCred, self, "enable")
|
||||
}
|
||||
|
||||
// 启用资源
|
||||
func (self *SEnabledStatusStandaloneResourceBase) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, true)
|
||||
if err != nil {
|
||||
@@ -59,6 +60,7 @@ func (self *SEnabledStatusStandaloneResourceBase) AllowPerformDisable(ctx contex
|
||||
return IsAdminAllowPerform(userCred, self, "disable")
|
||||
}
|
||||
|
||||
// 禁用资源
|
||||
func (self *SEnabledStatusStandaloneResourceBase) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) (jsonutils.JSONObject, error) {
|
||||
err := EnabledPerformEnable(self, ctx, userCred, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -70,12 +70,12 @@ func (model *SInfrasResourceBase) IsShared() bool {
|
||||
return SharableModelIsShared(model)
|
||||
}
|
||||
|
||||
func (model *SInfrasResourceBase) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) bool {
|
||||
func (model *SInfrasResourceBase) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (model *SInfrasResourceBase) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
err := SharablePerformPublic(model.GetIInfrasModel(), ctx, userCred, input)
|
||||
func (model *SInfrasResourceBase) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
err := SharablePerformPublic(model.GetIInfrasModel(), ctx, userCred, apis.PerformPublicProjectInput{PerformPublicDomainInput: input})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SharablePerformPublic")
|
||||
}
|
||||
|
||||
@@ -376,8 +376,7 @@ func (m SSharableBaseResource) GetPublicScope() rbacutils.TRbacScope {
|
||||
return rbacutils.String2Scope(m.PublicScope)
|
||||
}
|
||||
|
||||
func SharablePerformPublic(model ISharableBaseModel, ctx context.Context, userCred mcclient.TokenCredential, input apis.PerformPublicInput) error {
|
||||
log.Debugf("%s", jsonutils.Marshal(input))
|
||||
func SharablePerformPublic(model ISharableBaseModel, ctx context.Context, userCred mcclient.TokenCredential, input apis.PerformPublicProjectInput) error {
|
||||
var err error
|
||||
|
||||
resourceScope := model.GetModelManager().ResourceScope()
|
||||
@@ -394,9 +393,8 @@ func SharablePerformPublic(model ISharableBaseModel, ctx context.Context, userCr
|
||||
targetScope = rbacutils.ScopeDomain
|
||||
}
|
||||
|
||||
shareResult := apis.PerformPublicInput{
|
||||
Scope: string(targetScope),
|
||||
}
|
||||
shareResult := apis.PerformPublicProjectInput{}
|
||||
shareResult.Scope = string(targetScope)
|
||||
|
||||
candidateIds := model.GetSharableTargetDomainIds()
|
||||
requireIds := model.GetRequiredSharedDomainIds()
|
||||
|
||||
@@ -65,11 +65,11 @@ func (model *SSharableVirtualResourceBase) IsShared() bool {
|
||||
return SharableModelIsShared(model)
|
||||
}
|
||||
|
||||
func (model *SSharableVirtualResourceBase) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) bool {
|
||||
func (model *SSharableVirtualResourceBase) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicProjectInput) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (model *SSharableVirtualResourceBase) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
func (model *SSharableVirtualResourceBase) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicProjectInput) (jsonutils.JSONObject, error) {
|
||||
err := SharablePerformPublic(model.GetISharableVirtualModel(), ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SharablePerformPublic")
|
||||
|
||||
@@ -361,97 +361,88 @@ func (model *SStandaloneResourceBase) AllowGetDetailsMetadata(ctx context.Contex
|
||||
return IsAllowGetSpec(rbacutils.ScopeSystem, userCred, model, "metadata")
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) GetDetailsMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
fields := jsonutils.GetQueryStringArray(query, "field")
|
||||
val, err := Metadata.GetAll(model, fields, userCred)
|
||||
// 获取资源标签(元数据)
|
||||
func (model *SStandaloneResourceBase) GetDetailsMetadata(ctx context.Context, userCred mcclient.TokenCredential, input apis.GetMetadataInput) (apis.GetMetadataOutput, error) {
|
||||
val, err := Metadata.GetAll(model, input.Field, userCred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "Metadata.GetAll")
|
||||
}
|
||||
return jsonutils.Marshal(val), nil
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) AllowPerformMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return IsAllowPerform(rbacutils.ScopeSystem, userCred, model, "metadata")
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) PerformMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
dict, ok := data.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, httperrors.NewInputParameterError("input data not key value dict")
|
||||
}
|
||||
dictMap, err := dict.GetMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// +onecloud:swagger-gen-ignore
|
||||
func (model *SStandaloneResourceBase) PerformMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformMetadataInput) (jsonutils.JSONObject, error) {
|
||||
dictStore := make(map[string]interface{})
|
||||
for k, v := range dictMap {
|
||||
for k, v := range input {
|
||||
// 已双下滑线开头的metadata是系统内置,普通用户不可添加,只能查看
|
||||
if strings.HasPrefix(k, SYS_TAG_PREFIX) && (userCred == nil || !IsAllowPerform(rbacutils.ScopeSystem, userCred, model, "metadata")) {
|
||||
return nil, httperrors.NewForbiddenError("not allow to set system key, please remove the underscore at the beginning")
|
||||
}
|
||||
dictStore[k], _ = v.GetString()
|
||||
dictStore[k] = v
|
||||
}
|
||||
err = model.SetAllMetadata(ctx, dictStore, userCred)
|
||||
return nil, err
|
||||
err := model.SetAllMetadata(ctx, dictStore, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SetAllMetadata")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) AllowPerformUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return IsAllowPerform(rbacutils.ScopeSystem, userCred, model, "user-metadata")
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) PerformUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
dict, ok := data.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, httperrors.NewInputParameterError("input data not key value dict")
|
||||
}
|
||||
dictMap, err := dict.GetMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 更新资源的用户标签
|
||||
// +onecloud:swagger-gen-ignore
|
||||
func (model *SStandaloneResourceBase) PerformUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformUserMetadataInput) (jsonutils.JSONObject, error) {
|
||||
dictStore := make(map[string]interface{})
|
||||
for k, v := range dictMap {
|
||||
dictStore[USER_TAG_PREFIX+k], _ = v.GetString()
|
||||
for k, v := range input {
|
||||
dictStore[USER_TAG_PREFIX+k] = v
|
||||
}
|
||||
err = model.SetUserMetadataValues(ctx, dictStore, userCred)
|
||||
return nil, err
|
||||
err := model.SetUserMetadataValues(ctx, dictStore, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SetUserMetadataValues")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) AllowPerformSetUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return IsAllowPerform(rbacutils.ScopeSystem, userCred, model, "set-user-metadata")
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) PerformSetUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
dict, ok := data.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, httperrors.NewInputParameterError("input data not key value dict")
|
||||
}
|
||||
dictMap, err := dict.GetMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 全量替换资源的所有用户标签
|
||||
func (model *SStandaloneResourceBase) PerformSetUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformSetUserMetadataInput) (jsonutils.JSONObject, error) {
|
||||
dictStore := make(map[string]interface{})
|
||||
for k, v := range dictMap {
|
||||
dictStore[USER_TAG_PREFIX+k], _ = v.GetString()
|
||||
for k, v := range input {
|
||||
dictStore[USER_TAG_PREFIX+k] = v
|
||||
}
|
||||
err = model.SetUserMetadataAll(ctx, dictStore, userCred)
|
||||
return nil, err
|
||||
err := model.SetUserMetadataAll(ctx, dictStore, userCred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SetUserMetadataAll")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
model.SResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
|
||||
jsonMeta, _ := data.Get("__meta__")
|
||||
if jsonMeta != nil {
|
||||
model.PerformMetadata(ctx, userCred, nil, jsonMeta)
|
||||
meta := make(map[string]string)
|
||||
err := data.Unmarshal(&meta, "__meta__")
|
||||
if err == nil {
|
||||
model.PerformMetadata(ctx, userCred, nil, meta)
|
||||
}
|
||||
}
|
||||
|
||||
func (model *SStandaloneResourceBase) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
model.SResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
|
||||
jsonMeta, _ := data.Get("__meta__")
|
||||
if jsonMeta != nil {
|
||||
model.PerformMetadata(ctx, userCred, nil, jsonMeta)
|
||||
meta := make(map[string]string)
|
||||
err := data.Unmarshal(&meta, "__meta__")
|
||||
if err == nil {
|
||||
model.PerformMetadata(ctx, userCred, nil, meta)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ func (model *SStatusResourceBase) IsInStatus(status ...string) bool {
|
||||
return IsAllowGetSpec(rbacutils.ScopeSystem, userCred, model, "status")
|
||||
}*/
|
||||
|
||||
// 获取资源状态
|
||||
func (model *SStatusResourceBase) GetDetailsStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (apis.GetDetailsStatusOutput, error) {
|
||||
ret := apis.GetDetailsStatusOutput{}
|
||||
ret.Status = model.Status
|
||||
|
||||
@@ -51,6 +51,7 @@ func (self *SStatusDomainLevelResourceBase) AllowPerformStatus(ctx context.Conte
|
||||
return IsDomainAllowPerform(userCred, self, "status")
|
||||
}
|
||||
|
||||
// 更新资源状态
|
||||
func (self *SStatusDomainLevelResourceBase) PerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformStatusInput) (jsonutils.JSONObject, error) {
|
||||
err := StatusBasePerformStatus(self, userCred, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -51,6 +51,7 @@ func (self *SStatusInfrasResourceBase) AllowPerformStatus(ctx context.Context, u
|
||||
return IsDomainAllowPerform(userCred, self, "status")
|
||||
}
|
||||
|
||||
// 更新资源状态
|
||||
func (self *SStatusInfrasResourceBase) PerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformStatusInput) (jsonutils.JSONObject, error) {
|
||||
err := StatusBasePerformStatus(self, userCred, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -51,6 +51,7 @@ func (self *SStatusStandaloneResourceBase) AllowPerformStatus(ctx context.Contex
|
||||
return IsAdminAllowPerform(userCred, self, "status")
|
||||
}
|
||||
|
||||
// 更新资源状态
|
||||
func (self *SStatusStandaloneResourceBase) PerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformStatusInput) (jsonutils.JSONObject, error) {
|
||||
err := StatusBasePerformStatus(self, userCred, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -1986,7 +1986,7 @@ func (account *SCloudaccount) PerformPublic(ctx context.Context, userCred mcclie
|
||||
return nil, errors.Wrap(httperrors.ErrInputParameter, "share_mode cannot be account_domain")
|
||||
}
|
||||
|
||||
_, err := account.SInfrasResourceBase.PerformPublic(ctx, userCred, query, input.PerformPublicInput)
|
||||
_, err := account.SInfrasResourceBase.PerformPublic(ctx, userCred, query, input.PerformPublicDomainInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SInfrasResourceBase.PerformPublic")
|
||||
}
|
||||
@@ -2062,7 +2062,7 @@ func (account *SCloudaccount) PerformShareMode(ctx context.Context, userCred mcc
|
||||
} else {
|
||||
input2 := api.CloudaccountPerformPublicInput{
|
||||
ShareMode: input.ShareMode,
|
||||
PerformPublicInput: apis.PerformPublicInput{
|
||||
PerformPublicDomainInput: apis.PerformPublicDomainInput{
|
||||
Scope: string(rbacutils.ScopeSystem),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCloudproviderQuotaManager struct {
|
||||
db.SStandaloneResourceBaseManager
|
||||
db.SExternalizedResourceBaseManager
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCloudproviderCapabilityManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ func (gt *SGuestTemplate) PerformPublic(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data apis.PerformPublicInput,
|
||||
data apis.PerformPublicProjectInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
|
||||
// image, network, secgroup, instancegroup
|
||||
|
||||
@@ -100,7 +100,7 @@ type SHost struct {
|
||||
AccessIp string `width:"16" charset:"ascii" nullable:"true" list:"domain"`
|
||||
|
||||
// 管理地址
|
||||
ManagerUri string `width:"256" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain"`
|
||||
ManagerUri string `width:"256" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
|
||||
|
||||
// 系统信息
|
||||
SysInfo jsonutils.JSONObject `nullable:"true" search:"domain" list:"domain" update:"domain" create:"domain_optional"`
|
||||
@@ -5005,7 +5005,7 @@ func (host *SHost) GetUsages() []db.IUsage {
|
||||
}
|
||||
}
|
||||
|
||||
func (host *SHost) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
func (host *SHost) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
// perform public for all connected local storage
|
||||
storages := host.GetAttachedLocalStorages()
|
||||
for i := range storages {
|
||||
|
||||
@@ -32,6 +32,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SInstanceSnapshotJoint struct {
|
||||
db.SVirtualJointResourceBase
|
||||
|
||||
@@ -40,6 +41,7 @@ type SInstanceSnapshotJoint struct {
|
||||
DiskIndex int8 `nullable:"false" default:"0" list:"user" create:"required"`
|
||||
}
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SInstanceSnapshotJointManager struct {
|
||||
db.SVirtualJointResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SAwsCachedLbManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SAwsCachedLbbgManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCachedLoadbalancerAclManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SSharableVirtualResourceBaseManager
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCachedLoadbalancerCertificateManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SHuaweiCachedLbManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SHuaweiCachedLbbgManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SQcloudCachedLbManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SQcloudCachedLbbgManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SVirtualResourceBaseManager
|
||||
|
||||
@@ -1454,7 +1454,7 @@ func (self *SStorage) StartDeleteRbdDisks(ctx context.Context, userCred mcclient
|
||||
return nil
|
||||
}
|
||||
|
||||
func (storage *SStorage) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
func (storage *SStorage) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
// not allow to perform public for locally connected storage
|
||||
if storage.IsLocal() {
|
||||
hosts := storage.GetAttachedHosts()
|
||||
@@ -1465,7 +1465,7 @@ func (storage *SStorage) PerformPublic(ctx context.Context, userCred mcclient.To
|
||||
return storage.performPublicInternal(ctx, userCred, query, input)
|
||||
}
|
||||
|
||||
func (storage *SStorage) performPublicInternal(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
func (storage *SStorage) performPublicInternal(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
return storage.SEnabledStatusInfrasResourceBase.PerformPublic(ctx, userCred, query, input)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SVCenterManager struct {
|
||||
db.SEnabledStatusStandaloneResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ func (self *SGuestImage) PerformPublic(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input apis.PerformPublicInput,
|
||||
input apis.PerformPublicProjectInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
images, err := GuestImageJointManager.GetImagesByGuestImageId(self.Id)
|
||||
if err != nil {
|
||||
|
||||
@@ -1359,9 +1359,8 @@ func (self *SImage) PerformMarkStandard(
|
||||
}
|
||||
isStandard := jsonutils.QueryBoolean(data, "is_standard", false)
|
||||
if !self.IsStandard.IsTrue() && isStandard {
|
||||
input := apis.PerformPublicInput{
|
||||
Scope: "system",
|
||||
}
|
||||
input := apis.PerformPublicProjectInput{}
|
||||
input.Scope = "system"
|
||||
_, err := self.PerformPublic(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "PerformPublic")
|
||||
@@ -1445,7 +1444,7 @@ func (img *SImage) GetUsages() []db.IUsage {
|
||||
}
|
||||
}
|
||||
|
||||
func (img *SImage) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
func (img *SImage) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicProjectInput) (jsonutils.JSONObject, error) {
|
||||
if img.IsStandard.IsTrue() {
|
||||
return nil, errors.Wrap(httperrors.ErrForbidden, "cannot perform public for standard image")
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SAssignmentManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SConfigOptionManager struct {
|
||||
db.SResourceBaseManager
|
||||
IsSensitive bool
|
||||
|
||||
@@ -16,6 +16,7 @@ package models
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SFederatedUserManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -338,18 +338,19 @@ func (group *SGroup) UnlinkIdp(idpId string) error {
|
||||
func (group *SGroup) AllowPerformJoin(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SJoinProjectsInput,
|
||||
) bool {
|
||||
return db.IsAdminAllowPerform(userCred, group, "join")
|
||||
}
|
||||
|
||||
// 组加入项目
|
||||
func (group *SGroup) PerformJoin(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SJoinProjectsInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
err := joinProjects(group, false, ctx, userCred, data)
|
||||
err := joinProjects(group, false, ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,18 +360,19 @@ func (group *SGroup) PerformJoin(
|
||||
func (group *SGroup) AllowPerformLeave(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SLeaveProjectsInput,
|
||||
) bool {
|
||||
return db.IsAdminAllowPerform(userCred, group, "leave")
|
||||
}
|
||||
|
||||
// 组退出项目
|
||||
func (group *SGroup) PerformLeave(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SLeaveProjectsInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
err := leaveProjects(group, false, ctx, userCred, data)
|
||||
err := leaveProjects(group, false, ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -442,3 +444,75 @@ func (group *SGroup) PostCreate(
|
||||
log.Errorf("CancelPendingUsage fail %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (group *SGroup) AllowPerformAddUsers(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input api.PerformGroupAddUsersInput,
|
||||
) bool {
|
||||
return db.IsDomainAllowPerform(userCred, group, "add-users")
|
||||
}
|
||||
|
||||
// 组添加用户
|
||||
func (group *SGroup) PerformAddUsers(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input api.PerformGroupAddUsersInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
users := make([]*SUser, 0)
|
||||
for _, uid := range input.User {
|
||||
usr, err := UserManager.FetchByIdOrName(userCred, uid)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, errors.Wrapf(httperrors.ErrResourceNotFound, "user %s", uid)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "UserManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
users = append(users, usr.(*SUser))
|
||||
}
|
||||
for i := range users {
|
||||
err := UsergroupManager.add(ctx, userCred, users[i], group)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "UsergroupManager.add")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (group *SGroup) AllowPerformRemoveUsers(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input api.PerformGroupRemoveUsersInput,
|
||||
) bool {
|
||||
return db.IsDomainAllowPerform(userCred, group, "remove-users")
|
||||
}
|
||||
|
||||
// 组删除用户
|
||||
func (group *SGroup) PerformRemoveUsers(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
input api.PerformGroupRemoveUsersInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
users := make([]*SUser, 0)
|
||||
for _, uid := range input.User {
|
||||
usr, err := UserManager.FetchByIdOrName(userCred, uid)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, errors.Wrapf(httperrors.ErrResourceNotFound, "user %s", uid)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "UserManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
users = append(users, usr.(*SUser))
|
||||
}
|
||||
for i := range users {
|
||||
err := UsergroupManager.remove(ctx, userCred, users[i], group)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "UsergroupManager.add")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SIdmappingManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -225,10 +225,12 @@ func (ident *SIdentityProvider) getDriverClass() driver.IIdentityBackendClass {
|
||||
return driver.GetDriverClass(ident.Driver)
|
||||
}
|
||||
|
||||
// 配置认证源
|
||||
func (ident *SIdentityProvider) AllowPerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) bool {
|
||||
return db.IsAdminAllowUpdateSpec(userCred, ident, "config")
|
||||
}
|
||||
|
||||
// 配置认证源
|
||||
func (ident *SIdentityProvider) PerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) (jsonutils.JSONObject, error) {
|
||||
if ident.Status == api.IdentityDriverStatusConnected && ident.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("cannot update config when enabled and connected")
|
||||
@@ -408,6 +410,7 @@ func (self *SIdentityProvider) AllowPerformSync(ctx context.Context, userCred mc
|
||||
return db.IsAdminAllowPerform(userCred, self, "sync")
|
||||
}
|
||||
|
||||
// 手动同步认证源
|
||||
func (self *SIdentityProvider) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if !self.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Account disabled")
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SLocalUserManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/seclib2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SPasswordManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
@@ -199,12 +199,12 @@ func (policy *SPolicy) IsShared() bool {
|
||||
return db.SharableModelIsShared(policy)
|
||||
}
|
||||
|
||||
func (policy *SPolicy) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) bool {
|
||||
func (policy *SPolicy) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (policy *SPolicy) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
err := db.SharablePerformPublic(policy, ctx, userCred, input)
|
||||
func (policy *SPolicy) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
err := db.SharablePerformPublic(policy, ctx, userCred, apis.PerformPublicProjectInput{PerformPublicDomainInput: input})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SharablePerformPublic")
|
||||
}
|
||||
|
||||
@@ -471,14 +471,9 @@ func (project *SProject) PerformJoin(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SProjectAddUserGroupInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
input := api.SProjectAddUserGroupInput{}
|
||||
err := data.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("unmarshal project add user group input error %s", err)
|
||||
}
|
||||
err = input.Validate()
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
@@ -551,14 +546,9 @@ func (project *SProject) PerformLeave(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SProjectRemoveUserGroupInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
input := api.SProjectRemoveUserGroupInput{}
|
||||
err := data.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("unmarshal project remove usergroup input error %s", err)
|
||||
}
|
||||
err = input.Validate()
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
|
||||
@@ -419,12 +419,12 @@ func (role *SRole) IsSharable(reqUsrId mcclient.IIdentityProvider) bool {
|
||||
return db.SharableModelIsSharable(role, reqUsrId)
|
||||
}
|
||||
|
||||
func (role *SRole) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) bool {
|
||||
func (role *SRole) AllowPerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (role *SRole) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicInput) (jsonutils.JSONObject, error) {
|
||||
err := db.SharablePerformPublic(role, ctx, userCred, input)
|
||||
func (role *SRole) PerformPublic(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformPublicDomainInput) (jsonutils.JSONObject, error) {
|
||||
err := db.SharablePerformPublic(role, ctx, userCred, apis.PerformPublicProjectInput{PerformPublicDomainInput: input})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SharablePerformPublic")
|
||||
}
|
||||
|
||||
@@ -835,32 +835,27 @@ func (user *SUser) UnlinkIdp(idpId string) error {
|
||||
func (user *SUser) AllowPerformJoin(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SJoinProjectsInput,
|
||||
) bool {
|
||||
return db.IsAdminAllowPerform(userCred, user, "join")
|
||||
}
|
||||
|
||||
// 用户加入项目
|
||||
func (user *SUser) PerformJoin(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SJoinProjectsInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
err := joinProjects(user, true, ctx, userCred, data)
|
||||
err := joinProjects(user, true, ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func joinProjects(ident db.IModel, isUser bool, ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject) error {
|
||||
input := api.SJoinProjectsInput{}
|
||||
err := data.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return httperrors.NewInputParameterError("unmarshal input error %s", err)
|
||||
}
|
||||
|
||||
err = input.Validate()
|
||||
func joinProjects(ident db.IModel, isUser bool, ctx context.Context, userCred mcclient.TokenCredential, input api.SJoinProjectsInput) error {
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
return httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
@@ -910,30 +905,26 @@ func joinProjects(ident db.IModel, isUser bool, ctx context.Context, userCred mc
|
||||
func (user *SUser) AllowPerformLeave(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SLeaveProjectsInput,
|
||||
) bool {
|
||||
return db.IsAdminAllowPerform(userCred, user, "leave")
|
||||
}
|
||||
|
||||
// 用户退出项目
|
||||
func (user *SUser) PerformLeave(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
input api.SLeaveProjectsInput,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
err := leaveProjects(user, true, ctx, userCred, data)
|
||||
err := leaveProjects(user, true, ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func leaveProjects(ident db.IModel, isUser bool, ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject) error {
|
||||
input := api.SLeaveProjectsInput{}
|
||||
err := data.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return httperrors.NewInputParameterError("unmarshal leave porject input error: %s", err)
|
||||
}
|
||||
func leaveProjects(ident db.IModel, isUser bool, ctx context.Context, userCred mcclient.TokenCredential, input api.SLeaveProjectsInput) error {
|
||||
for i := range input.ProjectRoles {
|
||||
projObj, err := ProjectManager.FetchByIdOrName(userCred, input.ProjectRoles[i].Project)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user