Skip to content

Commit

Permalink
Merge pull request #45 from Mehonoshin/admin-create-users
Browse files Browse the repository at this point in the history
Admin create users
  • Loading branch information
Mehonoshin authored Jan 19, 2019
2 parents 2ebfe71 + 1fcb1e5 commit f03ed68
Show file tree
Hide file tree
Showing 100 changed files with 1,459 additions and 981 deletions.
19 changes: 19 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
SECRET_TOKEN=

EMAIL_USER=
EMAIL_PASS=
EMAIL_FROM=

ROLLBAR_ACCESS_TOKEN=

NEWRELIC_LICENSE_KEY=

ROBOKASSA_LOGIN=
ROBOKASSA_SECRET1=
ROBOKASSA_SECRET2=

WEBMONEY_SECRET=
WEBMONEY_WALLET_WMZ=
WEBMONEY_WALLET_WMR=

MAILCHIMP_API_KEY=
MAILCHIMP_ALL_CLIENTS_LIST_ID=
14 changes: 13 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
SECRET_TOKEN=0e89a81d2e7be3cce9c45d154df16269b5878061c9967c15329adf1490941e613f0b24dd4955b9e0b0e1356180ae8314b879f20150abad78e1ff4bc039a06d75
SECRET_TOKEN='0e89a81d2e7be3cce9c45d154df16269b5878061c9967c15329adf1490941e613f0b24dd4955b9e0b0e1356180ae8314b879f20150abad78e1ff4bc039a06d75'
DEFAULT_HOST='smartvpn.dev'
EMAIL_FROM='[email protected]'

ROBOKASSA_LOGIN='login'
ROBOKASSA_SECRET1='password'
ROBOKASSA_SECRET2='password2'

WEBMONEY_SECRET='secret value'
WEBMONEY_WALLET_WMZ='Z1234567890'

MAILCHIMP_API_KEY='mailchimp-key'
MAILCHIMP_ALL_CLIENTS_LIST_ID='test'
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist: xenial
language: ruby
sudo: true
cache: bundler

rvm:
- 2.1.1
Expand All @@ -11,15 +12,19 @@ matrix:
allow_failures:
- rvm: 2.1.1
- rvm: 2.6.0

addons:
chrome: stable

services:
- postgresql
- redis-server

before_install:
- gem install bundler -v '1.17.3'
- cp config/database.yml.sample config/database.yml
- cp .env.test .env

before_script:
- bundle exec rake db:create
- bundle exec rake db:schema:load
Expand All @@ -29,7 +34,5 @@ before_script:
- sudo apt-get --only-upgrade install google-chrome-stable
- sudo cp chromedriver /usr/local/bin/.
- sudo chmod +x /usr/local/bin/chromedriver
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3

script: bundle exec rspec
16 changes: 6 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ gem 'whenever', '0.9.0', require: false
gem 'sidekiq'
gem 'sinatra', require: false

# TODO: make it optional via ENV flag
gem 'rollbar'
# TODO: make it optional via ENV flag
gem 'newrelic_rpm'
Expand All @@ -65,7 +64,6 @@ gem 'jbuilder', '~> 1.0.1'
gem 'puma'

group :development do
gem 'awesome_print'
gem 'better_errors'
gem 'foreman'
gem 'letter_opener'
Expand All @@ -76,20 +74,18 @@ group :development do
end

group :test, :development do
gem 'awesome_print'
gem 'capybara'
gem 'database_cleaner', '1.0.0.RC1'
gem 'hirb'
gem 'mocha', require: false
gem 'rb-fchange', require: false
gem 'vcr'
# TODO: switch to stable version
gem 'dotenv-rails'
gem 'factory_girl_rails', '~> 4.0'
gem 'faker'
gem 'pry-rails'
gem 'rspec-rails'
gem 'rspec-its'
gem 'rspec-rails', '~> 3.8'
gem 'shoulda-matchers', '4.0.0.rc1'
gem 'vcr'
# TODO: switch to stable version
gem 'selenium-webdriver'
gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers'
gem 'timecop'
end

Expand Down
35 changes: 9 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ GIT
specs:
state_machine (1.2.0)

GIT
remote: git://github.com/thoughtbot/shoulda-matchers.git
revision: 380d18f0621c66a79445ebc6dcc0048fcc969911
specs:
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)

GEM
remote: http://rubygems.org/
specs:
Expand Down Expand Up @@ -83,7 +76,7 @@ GEM
ast (2.4.0)
autoprefixer-rails (9.4.4)
execjs
awesome_print (1.6.1)
awesome_print (1.8.0)
bcrypt (3.1.12)
better_errors (0.8.0)
coderay (>= 1.0.0)
Expand Down Expand Up @@ -170,7 +163,6 @@ GEM
activesupport (>= 4.2.0)
gyoku (1.1.1)
builder (>= 2.1.2)
hirb (0.7.1)
http-cookie (1.0.2)
domain_name (~> 0.5)
httparty (0.13.3)
Expand Down Expand Up @@ -220,17 +212,13 @@ GEM
nokogiri (~> 1.4)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
metaclass (0.0.1)
method_source (0.9.2)
migration_opener (0.0.2)
rails
mime-types (1.25.1)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
mixlib-cli (1.4.0)
mocha (0.13.3)
metaclass (~> 0.0.1)
money (6.5.0)
i18n (>= 0.6.4, <= 0.7.0)
multi_json (1.13.1)
Expand All @@ -254,11 +242,6 @@ GEM
activerecord (>= 3.0)
popper_js (1.14.5)
powerpack (0.1.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
puma (3.12.0)
rack (1.6.11)
rack-protection (1.5.5)
Expand Down Expand Up @@ -301,8 +284,6 @@ GEM
activesupport (>= 3.0)
i18n
polyamorous (~> 1.1)
rb-fchange (0.0.6)
ffi
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
Expand All @@ -319,6 +300,9 @@ GEM
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
Expand Down Expand Up @@ -379,6 +363,8 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-matchers (4.0.0.rc1)
activesupport (>= 4.2.0)
sidekiq (5.2.3)
connection_pool (~> 2.2, >= 2.2.2)
rack-protection (>= 1.5.0)
Expand Down Expand Up @@ -469,7 +455,6 @@ DEPENDENCIES
font-awesome-sass (~> 5.6.1)
foreman
gibbon
hirb
jbuilder (~> 1.0.1)
jquery-rails
jquery-ui-rails
Expand All @@ -478,25 +463,23 @@ DEPENDENCIES
letter_opener
mechanize
migration_opener
mocha
newrelic_rpm
pg
pghero
pry-rails
puma
rails (= 4.2.11)
rails-i18n
rails_config
ransack (= 1.5.1)
rb-fchange
rollbar
rspec-rails
rspec-its
rspec-rails (~> 3.8)
rubocop
russian_central_bank
sandi_meter
sass-rails
selenium-webdriver
shoulda-matchers!
shoulda-matchers (= 4.0.0.rc1)
show_for!
sidekiq
simple_form
Expand Down
88 changes: 44 additions & 44 deletions app/controllers/admin/servers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
class Admin::ServersController < Admin::BaseController
before_action :load_resource, only: [:show, :edit, :update, :destroy, :generate_config]
# frozen_string_literal: true

def index
@servers = Server.all
end
class Admin
class ServersController < Admin::BaseController
before_action :load_resource, only: %i[show edit update destroy generate_config]

def show
end
def index
@servers = Server.all
end

def new
@server = Server.new
end
def show; end

def create
@server = Server.new(resource_params)
if @server.save
redirect_to admin_servers_path, notice: "Сервер успешно добавлен"
else
render :new
def new
@server = Server.new
end
end

def edit
end
def create
@server = Server.new(resource_params)
if @server.save
redirect_to admin_servers_path, notice: t('admin.servers.notices.created')
else
render :new
end
end

def update
if @server.update(resource_params)
redirect_to admin_servers_path, notice: "Сервер успешно обновлен"
else
render :edit
def edit; end

def update
if @server.update(resource_params)
redirect_to admin_servers_path, notice: t('admin.servers.notices.updated')
else
render :edit
end
end
end

def destroy
@server.delete
redirect_to admin_servers_path, notice: "Сервер удален"
end
def destroy
@server.delete
redirect_to admin_servers_path, notice: t('admin.servers.notices.destroyed')
end

def generate_config
builder = ServerConfigBuilder.new(@server)
config_file = builder.generate_config
send_data config_file.to_text, filename: "#{@server.hostname}.ovpn"
end
def generate_config
builder = ServerConfigBuilder.new(server: @server)
config_file = builder.to_text
send_data config_file, filename: "#{@server.hostname}.ovpn"
end

private
private

def load_resource
@server = Server.find(params[:id])
end
def load_resource
@server = Server.find(params[:id])
end

def resource_params
params.require(:server).permit(:hostname, :ip_address, :state,
:config, :protocol, :port, :country_code,
plan_ids: []
)
def resource_params
params.require(:server).permit(:hostname, :ip_address, :state,
:config, :protocol, :port, :country_code,
plan_ids: [])
end
end
end

Loading

0 comments on commit f03ed68

Please sign in to comment.