mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
major code repair from old to new API -- WIP
This commit is contained in:
parent
25b576f861
commit
792c3e2ce8
46 changed files with 3403 additions and 171 deletions
|
@ -24,10 +24,10 @@ import (
|
|||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/domain/section/provider"
|
||||
"github.com/documize/community/server/web"
|
||||
)
|
||||
|
||||
// Authenticate user based up HTTP Authorization header.
|
||||
|
@ -98,7 +98,7 @@ func Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Attach user accounts and work out permissions
|
||||
attachUserAccounts(p, org.RefID, &user)
|
||||
AttachUserAccounts(p, org.RefID, &user)
|
||||
|
||||
// active check
|
||||
|
||||
|
@ -201,7 +201,7 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
|
||||
// Fetch user permissions for this org
|
||||
if context.Authenticated {
|
||||
user, err := getSecuredUser(p, org.RefID, context.UserID)
|
||||
user, err := GetSecuredUser(p, org.RefID, context.UserID)
|
||||
|
||||
if err != nil {
|
||||
writeServerError(w, method, err)
|
||||
|
@ -242,8 +242,6 @@ func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
|
||||
// ValidateAuthToken finds and validates authentication token.
|
||||
func ValidateAuthToken(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Info("cb gh")
|
||||
// TODO should this go after token validation?
|
||||
if s := r.URL.Query().Get("section"); s != "" {
|
||||
if err := provider.Callback(s, w, r); err != nil {
|
||||
|
@ -325,7 +323,7 @@ func ValidateAuthToken(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
user, err := getSecuredUser(p, org.RefID, context.UserID)
|
||||
user, err := GetSecuredUser(p, org.RefID, context.UserID)
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
@ -349,7 +347,7 @@ func preAuthorizeStaticAssets(r *http.Request) bool {
|
|||
strings.ToLower(r.URL.Path) == "/robots.txt" ||
|
||||
strings.ToLower(r.URL.Path) == "/version" ||
|
||||
strings.HasPrefix(strings.ToLower(r.URL.Path), "/api/public/") ||
|
||||
((api.Runtime.Flags.SiteMode == web.SiteModeSetup) && (strings.ToLower(r.URL.Path) == "/api/setup")) {
|
||||
((api.Runtime.Flags.SiteMode == env.SiteModeSetup) && (strings.ToLower(r.URL.Path) == "/api/setup")) {
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ func AuthenticateKeycloak(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Attach user accounts and work out permissions.
|
||||
attachUserAccounts(p, org.RefID, &user)
|
||||
AttachUserAccounts(p, org.RefID, &user)
|
||||
|
||||
// No accounts signals data integrity problem
|
||||
// so we reject login request.
|
||||
|
@ -301,7 +301,7 @@ func addUser(p request.Persister, u *entity.User, addSpace bool) (err error) {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
attachUserAccounts(p, p.Context.OrgID, &userDupe)
|
||||
AttachUserAccounts(p, p.Context.OrgID, &userDupe)
|
||||
|
||||
for _, a := range userDupe.Accounts {
|
||||
if a.OrgID == p.Context.OrgID {
|
||||
|
|
|
@ -136,7 +136,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
log.Info("Adding user")
|
||||
} else {
|
||||
attachUserAccounts(p, p.Context.OrgID, &userDupe)
|
||||
AttachUserAccounts(p, p.Context.OrgID, &userDupe)
|
||||
|
||||
for _, a := range userDupe.Accounts {
|
||||
if a.OrgID == p.Context.OrgID {
|
||||
|
@ -206,7 +206,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Send back new user record
|
||||
userModel, err = getSecuredUser(p, p.Context.OrgID, userID)
|
||||
userModel, err = GetSecuredUser(p, p.Context.OrgID, userID)
|
||||
|
||||
json, err := json.Marshal(userModel)
|
||||
if err != nil {
|
||||
|
@ -254,7 +254,7 @@ func GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
for i := range users {
|
||||
attachUserAccounts(p, p.Context.OrgID, &users[i])
|
||||
AttachUserAccounts(p, p.Context.OrgID, &users[i])
|
||||
}
|
||||
|
||||
json, err := json.Marshal(users)
|
||||
|
@ -333,7 +333,7 @@ func GetUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
user, err := getSecuredUser(p, p.Context.OrgID, userID)
|
||||
user, err := GetSecuredUser(p, p.Context.OrgID, userID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
writeNotFoundError(w, method, userID)
|
||||
|
@ -719,13 +719,14 @@ func ResetUserPassword(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Get user object contain associated accounts but credentials are wiped.
|
||||
func getSecuredUser(p request.Persister, orgID, user string) (u entity.User, err error) {
|
||||
func GetSecuredUser(p request.Persister, orgID, user string) (u entity.User, err error) {
|
||||
u, err = p.GetUser(user)
|
||||
attachUserAccounts(p, orgID, &u)
|
||||
AttachUserAccounts(p, orgID, &u)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func attachUserAccounts(p request.Persister, orgID string, user *entity.User) {
|
||||
func AttachUserAccounts(p request.Persister, orgID string, user *entity.User) {
|
||||
user.ProtectSecrets()
|
||||
a, err := p.GetUserAccounts(user.RefID)
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ import (
|
|||
|
||||
"github.com/documize/community/core/api"
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/server/web"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (p *Persister) GetOrganizationByDomain(subdomain string) (org entity.Organi
|
|||
err = nil
|
||||
subdomain = strings.ToLower(subdomain)
|
||||
|
||||
if api.Runtime.Flags.SiteMode == web.SiteModeNormal { // only return an organization when running normally
|
||||
if api.Runtime.Flags.SiteMode == env.SiteModeNormal { // only return an organization when running normally
|
||||
|
||||
var stmt *sqlx.Stmt
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue