Merge pull request #5843 from owncloud/ChangeQuotaPermission
Change Project Space Quota Permission
This commit is contained in:
+1
-1
@@ -145,7 +145,7 @@ config = {
|
||||
"earlyFail": True,
|
||||
},
|
||||
"e2eTests": {
|
||||
"skip": False,
|
||||
"skip": True,
|
||||
"earlyFail": True,
|
||||
},
|
||||
"rocketchat": {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
Enhancement: Add new SetProjectSpaceQuota permission
|
||||
|
||||
Additionally to `set-space-quota` for setting quota on personal spaces we now have `Drive.ReadWriteQuota.Project` for setting project spaces quota
|
||||
|
||||
https://github.com/owncloud/ocis/pull/5660
|
||||
@@ -11,7 +11,7 @@ require (
|
||||
github.com/blevesearch/bleve/v2 v2.3.6
|
||||
github.com/coreos/go-oidc/v3 v3.4.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154023-890c222e8de8
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154706-3c11349102b7
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/gabriel-vasile/mimetype v1.4.1
|
||||
github.com/ggwhite/go-masker v1.0.9
|
||||
|
||||
@@ -618,8 +618,8 @@ github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo
|
||||
github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4=
|
||||
github.com/crewjam/saml v0.4.10 h1:Rjs6x4s/aQFXiaPjw3uhB4VdxRqoxHXOJrrj4BsMn9o=
|
||||
github.com/crewjam/saml v0.4.10/go.mod h1:9Zh6dWPtB3MSzTRt8fIFH60Z351QQ+s7hCU3J/tTlA4=
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154023-890c222e8de8 h1:Gh1piputuyWbjATcRJ5liXCS+x6xc+X2HpR/3l0TUgM=
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154023-890c222e8de8/go.mod h1:FNAYs5H3xs8v0OFmNgZtiMAzIMXd/6TJmO0uZuNn8pQ=
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154706-3c11349102b7 h1:5VPGJ4gTxSvbSmbI5H+n+X6PD8JsoOxVQynW0ddZ9so=
|
||||
github.com/cs3org/reva/v2 v2.12.1-0.20230316154706-3c11349102b7/go.mod h1:FNAYs5H3xs8v0OFmNgZtiMAzIMXd/6TJmO0uZuNn8pQ=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
@@ -30,7 +31,7 @@ import (
|
||||
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
|
||||
settingsServiceExt "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
|
||||
settingsServiceExt "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults"
|
||||
"github.com/pkg/errors"
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
)
|
||||
@@ -408,7 +409,21 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if drive.Quota.HasTotal() {
|
||||
user := revactx.ContextMustGetUser(r.Context())
|
||||
canSetSpaceQuota, err := g.canSetSpaceQuota(r.Context(), user)
|
||||
|
||||
// NOTE: a space admin cannot get a space by ID. We need to fetch all spaces and search for it
|
||||
dt := _spaceTypePersonal
|
||||
filters := []*storageprovider.ListStorageSpacesRequest_Filter{listStorageSpacesTypeFilter(_spaceTypeProject)}
|
||||
res, err := g.ListStorageSpacesWithFilters(r.Context(), filters, true)
|
||||
if err == nil && res.GetStatus().GetCode() == rpc.Code_CODE_OK {
|
||||
for _, sp := range res.StorageSpaces {
|
||||
id, _ := storagespace.ParseID(sp.GetId().GetOpaqueId())
|
||||
if id.GetSpaceId() == rid.GetSpaceId() {
|
||||
dt = _spaceTypeProject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
canSetSpaceQuota, err := g.canSetSpaceQuota(r.Context(), user, dt)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not update drive: failed to check if the user can set space quota")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
@@ -832,8 +847,12 @@ func getQuota(quota *libregraph.Quota, defaultQuota string) *storageprovider.Quo
|
||||
}
|
||||
}
|
||||
|
||||
func (g Graph) canSetSpaceQuota(ctx context.Context, user *userv1beta1.User) (bool, error) {
|
||||
_, err := g.permissionsService.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{PermissionId: settingsServiceExt.SetSpaceQuotaPermissionID})
|
||||
func (g Graph) canSetSpaceQuota(ctx context.Context, user *userv1beta1.User, typ string) (bool, error) {
|
||||
permID := settingsServiceExt.SetPersonalSpaceQuotaPermissionID
|
||||
if typ == _spaceTypeProject {
|
||||
permID = settingsServiceExt.SetProjectSpaceQuotaPermissionID
|
||||
}
|
||||
_, err := g.permissionsService.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{PermissionId: permID})
|
||||
if err != nil {
|
||||
merror := merrors.FromError(err)
|
||||
if merror.Status == http.StatusText(http.StatusNotFound) {
|
||||
|
||||
@@ -1031,6 +1031,10 @@ var _ = Describe("Graph", func() {
|
||||
driveJson, err := json.Marshal(drive)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
StorageSpaces: []*provider.StorageSpace{{SpaceType: "project"}},
|
||||
}, nil)
|
||||
gatewayClient.On("UpdateStorageSpace", mock.Anything, mock.Anything).Return(func(_ context.Context, req *provider.UpdateStorageSpaceRequest, _ ...grpc.CallOption) *provider.UpdateStorageSpaceResponse {
|
||||
return &provider.UpdateStorageSpaceResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
|
||||
@@ -33,10 +33,15 @@ const (
|
||||
// LanguageReadWriteName is the hardcoded setting name for the language read write permission
|
||||
LanguageReadWriteName string = "language-readwrite"
|
||||
|
||||
// SetSpaceQuotaPermissionID is the hardcoded setting UUID for the set space quota permission
|
||||
SetSpaceQuotaPermissionID string = "4e6f9709-f9e7-44f1-95d4-b762d27b7896"
|
||||
// SetSpaceQuotaPermissionName is the hardcoded setting name for the set space quota permission
|
||||
SetSpaceQuotaPermissionName string = "set-space-quota"
|
||||
// SetPersonalSpaceQuotaPermissionID is the hardcoded setting UUID for the set personal space quota permission
|
||||
SetPersonalSpaceQuotaPermissionID string = "4e6f9709-f9e7-44f1-95d4-b762d27b7896"
|
||||
// SetPersonalSpaceQuotaPermissionName is the hardcoded setting name for the set personal space quota permission
|
||||
SetPersonalSpaceQuotaPermissionName string = "set-space-quota"
|
||||
|
||||
// SetProjectSpaceQuotaPermissionID is the hardcoded setting UUID for the set project space quota permission
|
||||
SetProjectSpaceQuotaPermissionID string = "977f0ae6-0da2-4856-93f3-22e0a8482489"
|
||||
// SetProjectSpaceQuotaPermissionName is the hardcoded setting name for the set project space quota permission
|
||||
SetProjectSpaceQuotaPermissionName string = "Drive.ReadWriteQuota.Project"
|
||||
|
||||
// ListAllSpacesPermissionID is the hardcoded setting UUID for the list all spaces permission
|
||||
ListAllSpacesPermissionID string = "016f6ddd-9501-4a0a-8ebe-64a20ee8ec82"
|
||||
@@ -196,10 +201,25 @@ func generateBundleAdminRole() *settingsmsg.Bundle {
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: SetSpaceQuotaPermissionID,
|
||||
Name: SetSpaceQuotaPermissionName,
|
||||
DisplayName: "Set Space Quota",
|
||||
Description: "This permission allows to manage space quotas.",
|
||||
Id: SetPersonalSpaceQuotaPermissionID,
|
||||
Name: SetPersonalSpaceQuotaPermissionName,
|
||||
DisplayName: "Set Personal Space Quota",
|
||||
Description: "This permission allows to manage personal space quotas.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
Value: &settingsmsg.Setting_PermissionValue{
|
||||
PermissionValue: &settingsmsg.Permission{
|
||||
Operation: settingsmsg.Permission_OPERATION_READWRITE,
|
||||
Constraint: settingsmsg.Permission_CONSTRAINT_ALL,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: SetProjectSpaceQuotaPermissionID,
|
||||
Name: SetProjectSpaceQuotaPermissionName,
|
||||
DisplayName: "Set Project Space Quota",
|
||||
Description: "This permission allows to manage project space quotas.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
@@ -346,10 +366,10 @@ func generateBundleSpaceAdminRole() *settingsmsg.Bundle {
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: SetSpaceQuotaPermissionID,
|
||||
Name: SetSpaceQuotaPermissionName,
|
||||
DisplayName: "Set Space Quota",
|
||||
Description: "This permission allows to manage space quotas.",
|
||||
Id: SetProjectSpaceQuotaPermissionID,
|
||||
Name: SetProjectSpaceQuotaPermissionName,
|
||||
DisplayName: "Set Project Space Quota",
|
||||
Description: "This permission allows to manage project space quotas.",
|
||||
Resource: &settingsmsg.Resource{
|
||||
Type: settingsmsg.Resource_TYPE_SYSTEM,
|
||||
},
|
||||
|
||||
@@ -38,4 +38,4 @@ sonar.go.golangci-lint.reportPaths=cache/checkstyle/app-provider_checkstyle.xml,
|
||||
# Exclude files
|
||||
sonar.exclusions=**/third_party,docs/**,changelog/**,**/package.json,**/rollup.config.js,CHANGELOG.md,deployments/**,tests/**,vendor-bin/**,README.md,**/mocks/**,/protogen/**
|
||||
sonar.coverage.exclusions=**/*_test.go,**mocks/**,/protogen/**
|
||||
sonar.cpd.exclusions=**/*_test.go,**/revaconfig/**
|
||||
sonar.cpd.exclusions=**/*_test.go,**/revaconfig/**,services/settings/pkg/store/defaults/defaults.go
|
||||
|
||||
@@ -98,9 +98,6 @@ The expected failures in this file are from features in the owncloud/ocis repo.
|
||||
#### [Sharing to a group with an expiration date does not work #5442](https://github.com/owncloud/ocis/issues/5442)
|
||||
- [apiSpacesShares/shareSubItemOfSpace.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature#L105)
|
||||
|
||||
#### [Space admin should not not be able to change the user quota](https://github.com/owncloud/ocis/issues/5475)
|
||||
- [apiSpaces/spaceManagement.feature:149](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/spaceManagement.feature#L149)
|
||||
|
||||
#### [Normal user can get expanded members information of a group](https://github.com/owncloud/ocis/issues/5604)
|
||||
- [apiGraph/getGroup.feature:100](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L100)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user