Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Greenlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arbeitsgruppe Hardwarenahe IT-Systeme
Greenlight
Commits
54d1c2f3
Unverified
Commit
54d1c2f3
authored
Feb 3, 2023
by
Ahmad Farhat
Committed by
GitHub
Feb 3, 2023
Browse files
Options
Downloads
Patches
Plain Diff
Make SMTP not required (#4749)
* Make SMTP not required * quick fix
parent
5ba77545
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/controllers/api/v1/users_controller.rb
+9
-4
9 additions, 4 deletions
app/controllers/api/v1/users_controller.rb
sample.env
+14
-14
14 additions, 14 deletions
sample.env
spec/controllers/users_controller_spec.rb
+31
-14
31 additions, 14 deletions
spec/controllers/users_controller_spec.rb
with
54 additions
and
32 deletions
app/controllers/api/v1/users_controller.rb
+
9
−
4
View file @
54d1c2f3
...
...
@@ -23,6 +23,7 @@ module Api
# POST /api/v1/users.json
# Creates and saves a new user record in the database with the provided parameters
def
create
smtp_enabled
=
ENV
[
'SMTP_SERVER'
].
present?
# Check if this is an admin creating a user
admin_create
=
current_user
&&
PermissionsChecker
.
new
(
current_user
:,
permission_names:
'ManageUsers'
,
current_provider
:).
call
...
...
@@ -37,6 +38,8 @@ module Api
user
=
UserCreator
.
new
(
user_params:
create_user_params
.
except
(
:invite_token
),
provider:
current_provider
,
role:
default_role
).
call
user
.
verify!
unless
smtp_enabled
# TODO: Add proper error logging for non-verified token hcaptcha
if
!
admin_create
&&
hcaptcha_enabled?
&&
!
verify_hcaptcha
(
response:
params
[
:token
])
return
render_error
errors:
Rails
.
configuration
.
custom_error_msgs
[
:hcaptcha_invalid
]
...
...
@@ -46,10 +49,12 @@ module Api
user
.
pending!
if
!
admin_create
&&
registration_method
==
SiteSetting
::
REGISTRATION_METHODS
[
:approval
]
if
user
.
save
if
smtp_enabled
token
=
user
.
generate_activation_token!
UserMailer
.
with
(
user
:,
expires_in:
User
::
ACTIVATION_TOKEN_VALIDITY_PERIOD
.
from_now
,
activation_url:
activate_account_url
(
token
),
base_url:
request
.
base_url
,
provider:
current_provider
).
activate_account_email
.
deliver_later
end
create_default_room
(
user
)
...
...
This diff is collapsed.
Click to expand it.
sample.env
+
14
−
14
View file @
54d1c2f3
...
...
@@ -20,23 +20,23 @@ DATABASE_URL=
# E.g. redis://redis:6379
REDIS_URL=
### OPTIONAL ENV VARS
### SMTP CONFIGURATION
# Emails are required for the basic features of Greenlight to function.
# Please refer to your SMTP provider to get the values for the variables below
SMTP_SENDER_EMAIL=
SMTP_SENDER_NAME=
SMTP_SERVER=
SMTP_PORT=
SMTP_DOMAIN=
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_AUTH=
SMTP_STARTTLS_AUTO=
SMTP_STARTTLS=
SMTP_TLS=
SMTP_SSL_VERIFY=
### OPTIONAL ENV VARS
#SMTP_SENDER_EMAIL=
#SMTP_SENDER_NAME=
#SMTP_SERVER=
#SMTP_PORT=
#SMTP_DOMAIN=
#SMTP_USERNAME=
#SMTP_PASSWORD=
#SMTP_AUTH=
#SMTP_STARTTLS_AUTO=true
#SMTP_STARTTLS=false
#SMTP_TLS=false
#SMTP_SSL_VERIFY=true
### EXTERNAL AUTHENTICATION METHODS
#
...
...
This diff is collapsed.
Click to expand it.
spec/controllers/users_controller_spec.rb
+
31
−
14
View file @
54d1c2f3
...
...
@@ -8,6 +8,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
let
(
:fake_setting_getter
)
{
instance_double
(
SettingGetter
)
}
before
do
ENV
[
'SMTP_SERVER'
]
=
'test.com'
request
.
headers
[
'ACCEPT'
]
=
'application/json'
end
...
...
@@ -63,6 +64,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end
context
'activation'
do
context
'SMTP enabled'
do
it
'generates an activation token for the user'
do
freeze_time
...
...
@@ -83,6 +85,21 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end
end
context
'SMTP disabled'
do
before
do
ENV
[
'SMTP_SERVER'
]
=
''
end
it
'marks the user as verified and signs them in'
do
post
:create
,
params:
user_params
user
=
User
.
find_by
email:
user_params
[
:user
][
:email
]
expect
(
user
).
to
be_verified
expect
(
session
[
:session_token
]).
to
eq
(
user
.
session_token
)
end
end
end
context
'Admin creation'
do
before
{
sign_in_user
(
user
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment