Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

User with the role Administrator or Collaborator can now log in, regardless of the oauth role

Albert Nimtz3d0a833a3e05
diff --git a/app/handlers/oauth.go b/app/handlers/oauth.go
index 4b2c7d3fa..24a97dcf2 100644
--- a/app/handlers/oauth.go
+++ b/app/handlers/oauth.go
@@ -110,14 +110,32 @@ func OAuthToken() web.HandlerFunc {
return c.Failure(err)
}
+ // Look up the existing Fider user first (by provider UID, then by email).
+ // We need this before the role check so that administrators and collaborators
+ // can always sign in regardless of OAuth role changes.
+ var user *entity.User
+
+ userByProvider := &query.GetUserByProvider{Provider: provider, UID: oauthUser.Result.ID}
+ err = bus.Dispatch(c, userByProvider)
+ user = userByProvider.Result
+
+ if errors.Cause(err) == app.ErrNotFound && oauthUser.Result.Email != "" {
+ userByEmail := &query.GetUserByEmail{Email: oauthUser.Result.Email}
+ err = bus.Dispatch(c, userByEmail)
+ user = userByEmail.Result
+ }
+
// Check if user has the required roles for this provider.
// Both AllowedRoles and JSONUserRolesPath must be set on the provider for the check to run.
+ // Administrators and collaborators already trusted in Fider are always allowed through,
+ // regardless of their current OAuth roles.
var providerRolesPath, providerAllowedRoles string
if customConfig != nil {
providerRolesPath = customConfig.JSONUserRolesPath
providerAllowedRoles = customConfig.AllowedRoles
}
- if !hasAllowedRole(oauthUser.Result.Roles, providerRolesPath, providerAllowedRoles) {
+ isFiderPrivileged := user != nil && (user.Role == enum.RoleAdministrator || user.Role == enum.RoleCollaborator)
+ if !isFiderPrivileged && !hasAllowedRole(oauthUser.Result.Roles, providerRolesPath, providerAllowedRoles) {
log.Warnf(c, "User @{UserID} attempted OAuth login but does not have required role. User roles: @{UserRoles}, Allowed roles: @{AllowedRoles}",
dto.Props{
"UserID": oauthUser.Result.ID,
@@ -126,18 +144,6 @@ func OAuthToken() web.HandlerFunc {
})
return c.Redirect("/access-denied")
}
-
- var user *entity.User
-
- userByProvider := &query.GetUserByProvider{Provider: provider, UID: oauthUser.Result.ID}
- err = bus.Dispatch(c, userByProvider)
- user = userByProvider.Result
-
- if errors.Cause(err) == app.ErrNotFound && oauthUser.Result.Email != "" {
- userByEmail := &query.GetUserByEmail{Email: oauthUser.Result.Email}
- err = bus.Dispatch(c, userByEmail)
- user = userByEmail.Result
- }
if err != nil {
if errors.Cause(err) == app.ErrNotFound {
isTrusted := customConfig != nil && customConfig.IsTrusted