Skip to content

Commit

Permalink
add get me endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Oct 27, 2023
1 parent e83bada commit 014070d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/http/services/owncloud/ocgraph/ocgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

// This package implements the APIs defined in https://owncloud.dev/apis/http/graph/spaces/
// This package implements the APIs defined in https://owncloud.dev/apis/http/graph/

package ocgraph

Expand Down Expand Up @@ -72,7 +72,10 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error)

func (s *svc) routerInit() error {
s.router.Route("/v1.0", func(r chi.Router) {
r.Get("/me/drives", s.listMySpaces)
r.Route("/me", func(r chi.Router) {
r.Get("", s.getMe)
r.Get("/drives", s.listMySpaces)
})
})
return nil
}
Expand Down
41 changes: 41 additions & 0 deletions internal/http/services/owncloud/ocgraph/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

// This package implements the APIs defined in https://owncloud.dev/apis/http/graph/

package ocgraph

import (
"encoding/json"
"net/http"

"github.com/cs3org/reva/pkg/appctx"
libregraph "github.com/owncloud/libre-graph-api-go"
)

// https://owncloud.dev/apis/http/graph/users/#reading-users
func (s *svc) getMe(w http.ResponseWriter, r *http.Request) {
user := appctx.ContextMustGetUser(r.Context())
me := &libregraph.User{
DisplayName: &user.DisplayName,
Mail: &user.Mail,
OnPremisesSamAccountName: &user.Username,
Id: &user.Id.OpaqueId,
}
_ = json.NewEncoder(w).Encode(me)
}

0 comments on commit 014070d

Please sign in to comment.