Graph test coverage drives (#5141)

* Add GetSingleDrive to the service interface

* Increase test coverage for the drives endpoint

* Remove dead code

* Add missing methods to the graph service interface

* Use the existing permission client of the graph service

* Increase test coverage
This commit is contained in:
Andre Duffeck
2022-11-29 10:21:25 +01:00
committed by GitHub
parent 1d4123f12c
commit e07c7bc808
6 changed files with 913 additions and 528 deletions

View File

@@ -337,8 +337,6 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
return
}
root := &storageprovider.ResourceId{}
rid, err := storagespace.ParseID(driveID)
if err != nil {
logger.Debug().Err(err).Interface("id", rid).Msg("could not update drive, invalid resource id")
@@ -346,7 +344,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
root = &rid
root := &rid
client := g.GetGatewayClient()
@@ -400,7 +398,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
if drive.Quota.HasTotal() {
user := ctxpkg.ContextMustGetUser(r.Context())
canSetSpaceQuota, err := canSetSpaceQuota(r.Context(), user)
canSetSpaceQuota, err := g.canSetSpaceQuota(r.Context(), user)
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())
@@ -771,9 +769,8 @@ func getQuota(quota *libregraph.Quota, defaultQuota string) *storageprovider.Quo
}
}
func canSetSpaceQuota(ctx context.Context, user *userv1beta1.User) (bool, error) {
settingsService := settingssvc.NewPermissionService("com.owncloud.api.settings", grpc.DefaultClient())
_, err := settingsService.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{PermissionId: settingsServiceExt.SetSpaceQuotaPermissionID})
func (g Graph) canSetSpaceQuota(ctx context.Context, user *userv1beta1.User) (bool, error) {
_, err := g.permissionsService.GetPermissionByID(ctx, &settingssvc.GetPermissionByIDRequest{PermissionId: settingsServiceExt.SetSpaceQuotaPermissionID})
if err != nil {
merror := merrors.FromError(err)
if merror.Status == http.StatusText(http.StatusNotFound) {

File diff suppressed because it is too large Load Diff

View File

@@ -104,6 +104,21 @@ func (i instrument) GetDrives(w http.ResponseWriter, r *http.Request) {
i.next.GetDrives(w, r)
}
// GetSingleDrive implements the Service interface.
func (i instrument) GetSingleDrive(w http.ResponseWriter, r *http.Request) {
i.next.GetDrives(w, r)
}
// UpdateDrive implements the Service interface.
func (i instrument) UpdateDrive(w http.ResponseWriter, r *http.Request) {
i.next.GetDrives(w, r)
}
// DeleteDrive implements the Service interface.
func (i instrument) DeleteDrive(w http.ResponseWriter, r *http.Request) {
i.next.GetDrives(w, r)
}
// GetAllDrives implements the Service interface.
func (i instrument) GetAllDrives(w http.ResponseWriter, r *http.Request) {
i.next.GetAllDrives(w, r)

View File

@@ -104,6 +104,21 @@ func (l logging) GetDrives(w http.ResponseWriter, r *http.Request) {
l.next.GetDrives(w, r)
}
// GetSingleDrive implements the Service interface.
func (l logging) GetSingleDrive(w http.ResponseWriter, r *http.Request) {
l.next.GetDrives(w, r)
}
// UpdateDrive implements the Service interface.
func (l logging) UpdateDrive(w http.ResponseWriter, r *http.Request) {
l.next.GetDrives(w, r)
}
// DeleteDrive implements the Service interface.
func (l logging) DeleteDrive(w http.ResponseWriter, r *http.Request) {
l.next.GetDrives(w, r)
}
// GetAllDrives implements the Service interface.
func (l logging) GetAllDrives(w http.ResponseWriter, r *http.Request) {
l.next.GetAllDrives(w, r)

View File

@@ -48,8 +48,11 @@ type Service interface {
DeleteGroupMember(http.ResponseWriter, *http.Request)
GetDrives(w http.ResponseWriter, r *http.Request)
GetSingleDrive(w http.ResponseWriter, r *http.Request)
GetAllDrives(w http.ResponseWriter, r *http.Request)
CreateDrive(w http.ResponseWriter, r *http.Request)
UpdateDrive(w http.ResponseWriter, r *http.Request)
DeleteDrive(w http.ResponseWriter, r *http.Request)
}
// NewService returns a service implementation for Service.

View File

@@ -100,6 +100,21 @@ func (t tracing) GetDrives(w http.ResponseWriter, r *http.Request) {
t.next.GetDrives(w, r)
}
// GetSingleDrive implements the Service interface.
func (t tracing) GetSingleDrive(w http.ResponseWriter, r *http.Request) {
t.next.GetDrives(w, r)
}
// UpdateDrive implements the Service interface.
func (t tracing) UpdateDrive(w http.ResponseWriter, r *http.Request) {
t.next.GetDrives(w, r)
}
// DeleteDrive implements the Service interface.
func (t tracing) DeleteDrive(w http.ResponseWriter, r *http.Request) {
t.next.GetDrives(w, r)
}
// GetAllDrives implements the Service interface.
func (t tracing) GetAllDrives(w http.ResponseWriter, r *http.Request) {
t.next.GetAllDrives(w, r)