Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
[WIP] fixing issue related to disabling user registration via an envi…
Browse files Browse the repository at this point in the history
…ronment variable
  • Loading branch information
rdingwell committed Nov 29, 2017
1 parent b382f5c commit 011fb53
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 17 deletions.
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,5 @@
},
"plugins": [
"react"
],
"globals": {
DISABLE_USER_REGISTRATION: 'false'
}
]
}
4 changes: 2 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ class RegistrationsController < Devise::RegistrationsController
respond_to :json

def create
if DISABLE_USER_REGISTRATION
if Settings.disable_user_registration
render json: { error: 'User registration is disabled.' }, status: :unprocessable_entity
else
super
end
end

def new
if DISABLE_USER_REGISTRATION
if Settings.disable_user_registration
render json: { error: 'User registration is disabled.' }, status: :unprocessable_entity
else
super
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module ApplicationHelper
include Devise::OmniAuth::UrlHelpers

def environment_tags
disable_ur = Settings.disable_user_registration
disable_ur = false if Settings.display_login
safe_join [(tag.meta name: 'DISABLE_LOGIN_UI', content: disable_ur),
(tag.meta name: 'environment', content: Rails.env)]
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<%= environment_tags %>
<%= csrf_meta_tags %>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">

Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/landing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script language="JavaScript" type="text/javascript" src="https://www.cdc.gov/JScript/metrics/topic_levels.js"></script>
<script language="JavaScript" type="text/javascript" src="https://www.cdc.gov/JScript/metrics/s_code_v21_cdcgov.js"></script>
<% end %>
<%= environment_tags %>
<%= csrf_meta_tags %>

<%= javascript_pack_tag 'babel-polyfill.js' %>
Expand Down
2 changes: 0 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.

DISABLE_USER_REGISTRATION = ENV['DISABLE_USER_REGISTRATION'] == 'true'
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
Expand Down
4 changes: 3 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ oid_prefix:
elasticsearch:
log: false

app_version: '1.0'
app_version: '1.2'


disable_user_registration: false
concept_service_url: 'http://concept-manager.129.83.185.216.xip.io'
1 change: 0 additions & 1 deletion config/webpack/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = merge(sharedConfig, {
}),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') },
DISABLE_USER_REGISTRATION: JSON.stringify(process.env.DISABLE_USER_REGISTRATION || 'false')
}),
new CompressionPlugin({
asset: '[path].gz[query]',
Expand Down
3 changes: 0 additions & 3 deletions config/webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ module.exports = {
$: "jquery",
jQuery: "jquery"
}),
new webpack.DefinePlugin({
DISABLE_USER_REGISTRATION: JSON.stringify(process.env.DISABLE_USER_REGISTRATION || 'false')
}),
],

resolve: {
Expand Down
17 changes: 15 additions & 2 deletions webpack/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ class App extends Component {
this.props.fetchStats();
}

disableUserRegistration() {
const metas = document.getElementsByTagName('meta');
let dur = true;
for (let i = 0; i < metas.length; i++) {
const meta = metas[i];
if (meta.getAttribute('name') === 'DISABLE_LOGIN_UI') {
dur = meta.getAttribute('content') == 'true';
}
}

return dur;
}

openLogInModal() {
this.setState({logInOpen: true});
}
Expand Down Expand Up @@ -82,7 +95,7 @@ class App extends Component {
element.focus();
}}>Skip to main content</a>
<Header currentUser={this.props.currentUser}
disableUserRegistration={DISABLE_USER_REGISTRATION}
disableUserRegistration={this.disableUserRegistration()}
location={this.props.location}
logInOpener={this.openLogInModal}
signUpOpener={this.openSignUpModal}
Expand All @@ -108,7 +121,7 @@ class App extends Component {
surveillanceSystems={this.props.surveillanceSystems}
surveillancePrograms={this.props.surveillancePrograms} />
<SettingsModal update={this.updateUser}
disableUserUpdate={DISABLE_USER_REGISTRATION}
disableUserUpdate={this.disableUserRegistration()}
show={this.state.settingsOpen}
closer={this.closeSettingsModal}
currentUser={this.props.currentUser}
Expand Down
2 changes: 1 addition & 1 deletion webpack/containers/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { fetchNotifications } from '../actions/notification_actions';
let LoginMenu = ({disableUserRegistration, logInOpener, signUpOpener, currentUser}) => {
let loggedIn = ! isEmpty(currentUser);
if(!loggedIn) {
if(disableUserRegistration == 'true') {
if(disableUserRegistration) {
return (
<ul className="nav navbar-nav">
<li className="log-in-link">
Expand Down

0 comments on commit 011fb53

Please sign in to comment.