Skip to content

Commit

Permalink
fetch appRoles for application from settings service
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Jan 4, 2023
1 parent f2ea32e commit 25ef08c
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions services/graph/pkg/service/v0/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
)

// GetApplication implements the Service interface.
func (g Graph) GetApplication(w http.ResponseWriter, r *http.Request) {
logger := g.logger.SubloggerWithRequestID(r.Context())
logger.Info().Interface("query", r.URL.Query()).Msg("calling get application")

// TODO make application id and name for this instance configurable
applicationID := chi.URLParam(r, "applicationID")

role1 := libregraph.NewAppRole("uuid-for-employee-role")
role1.SetDisplayName("Employee")
role2 := libregraph.NewAppRole("uuid-for-managemer-role")
role2.SetDisplayName("Manager")
role3 := libregraph.NewAppRole("uuid-for-staff-role")
role3.SetDisplayName("Staff")
role4 := libregraph.NewAppRole("uuid-for-student-role")
role4.SetDisplayName("Student")
role5 := libregraph.NewAppRole("uuid-for-admin-role")
role5.SetDisplayName("Administrator")
role5.SetDescription("Can administrate all aspects of an application")
role6 := libregraph.NewAppRole("uuid-for-guest-role")
role6.SetDisplayName("Guest")
role5.SetDescription("Can access shared resources, but has no personal drive")
role7 := libregraph.NewAppRole("uuid-for-configurator-role")
role7.SetDisplayName("Configurator")
s := settingssvc.NewRoleService("com.owncloud.api.settings", grpc.DefaultClient())

lbr, err := s.ListRoles(r.Context(), &settingssvc.ListBundlesRequest{})
if err != nil {
logger.Error().Err(err).Msg("could not list roles: transport error")
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}

roles := make([]libregraph.AppRole, 0, len(lbr.Bundles))
for _, bundle := range lbr.GetBundles() {
role := libregraph.NewAppRole(bundle.GetId())
role.SetDisplayName(bundle.GetDisplayName())
roles = append(roles, *role)
}

application := libregraph.NewApplication(applicationID)
application.SetAppRoles([]libregraph.AppRole{
*role1, *role2, *role3, *role4, *role5, *role6, *role7,
})
application.SetAppRoles(roles)

render.Status(r, http.StatusOK)
render.JSON(w, r, &ListResponse{Value: application})
Expand Down

0 comments on commit 25ef08c

Please sign in to comment.