mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.1.0 -> release/2.2.0
* commit 'ab8d120580317d802d6a1150c86b91bd0641a341': server create disk minor fix attach detach isolate device server attach detach network, change bandwidth, some bug fix guest desc, guest sendkey, fix disk delete
This commit is contained in:
@@ -955,10 +955,6 @@ func objectPerformAction(dispatcher *DBModelDispatcher, modelValue reflect.Value
|
||||
}
|
||||
|
||||
func updateItem(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if !item.AllowUpdateItem(ctx, userCred) {
|
||||
return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item"))
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
err = item.ValidateUpdateCondition(ctx)
|
||||
@@ -1030,6 +1026,10 @@ func (dispatcher *DBModelDispatcher) Update(ctx context.Context, idStr string, q
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
if !model.AllowUpdateItem(ctx, userCred) {
|
||||
return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item"))
|
||||
}
|
||||
|
||||
lockman.LockObject(ctx, model)
|
||||
defer lockman.ReleaseObject(ctx, model)
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ func (dispatcher *DBJointModelDispatcher) Get(ctx context.Context, id1 string, i
|
||||
} else if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if !item.AllowGetDetails(ctx, userCred, query) {
|
||||
if !item.AllowGetJointDetails(ctx, userCred, query, item) {
|
||||
return nil, httperrors.NewForbiddenError("Not allow to get details")
|
||||
}
|
||||
return getItemDetails(dispatcher.JointModelManager(), item, ctx, userCred, query)
|
||||
@@ -200,6 +200,11 @@ func (dispatcher *DBJointModelDispatcher) Update(ctx context.Context, id1 string
|
||||
} else if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
if !item.AllowUpdateJointItem(ctx, userCred, item) {
|
||||
return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item"))
|
||||
}
|
||||
|
||||
lockman.LockJointObject(ctx, master, slave)
|
||||
defer lockman.ReleaseJointObject(ctx, master, slave)
|
||||
return updateItem(dispatcher.JointModelManager(), item, ctx, userCred, query, data)
|
||||
|
||||
@@ -131,6 +131,8 @@ type IJointModel interface {
|
||||
Slave() IStandaloneModel
|
||||
|
||||
Detach(ctx context.Context, userCred mcclient.TokenCredential) error
|
||||
AllowGetJointDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, item IJointModel) bool
|
||||
AllowUpdateJointItem(ctx context.Context, userCred mcclient.TokenCredential, item IJointModel) bool
|
||||
}
|
||||
|
||||
type IStandaloneModelManager interface {
|
||||
|
||||
@@ -179,6 +179,16 @@ func (joint *SJointResourceBase) Slave() IStandaloneModel {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SJointResourceBase) AllowGetJointDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, item IJointModel) bool {
|
||||
masterVirtual := item.Master().(IVirtualModel)
|
||||
return masterVirtual.IsOwner(userCred)
|
||||
}
|
||||
|
||||
func (self *SJointResourceBase) AllowUpdateJointItem(ctx context.Context, userCred mcclient.TokenCredential, item IJointModel) bool {
|
||||
masterVirtual := item.Master().(IVirtualModel)
|
||||
return masterVirtual.IsOwner(userCred)
|
||||
}
|
||||
|
||||
/*
|
||||
func (joint *SJointResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := joint.SResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
|
||||
Reference in New Issue
Block a user