Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
spec/dummy/db/*.sqlite3
spec/dummy/db/*.sqlite3-journal
spec/dummy/log/*.log
spec/dummy/tmp/
.DS_Store
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.1
27 changes: 7 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
source 'https://rubygems.org'

# Declare your gem's dependencies in dynamic_forms.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use a debugger
# gem 'byebug', group: [:development, :test]
gem 'pg'
gem 'haml'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'pry'
gem 'pry-rails'
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'database_cleaner'
gem 'rails-controller-testing'
gem 'shoulda-matchers'
end


gem 'haml'
# Pagination


gem 'bootstrap', '~> 4.3.1'
gem 'font-awesome-sass', '~> 5.11.2'
gem 'jquery-rails'

# Slug
gem "kaminari"
gem "friendly_id", "~> 5.1.0"
gem "jquery-rails"
62 changes: 22 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
PATH
remote: .
specs:
dynamic_forms (0.1.0)
dynamic_forms (0.3.2)
friendly_id (~> 5.1.0)
jquery-rails
kaminari
rails (~> 5.1.0)

GEM
Expand Down Expand Up @@ -44,37 +47,25 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (8.0.0)
autoprefixer-rails (9.6.1.1)
execjs
bootstrap (4.3.1)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
builder (3.2.3)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
erubi (1.8.0)
execjs (2.7.0)
erubi (1.9.0)
factory_bot (5.1.0)
activesupport (>= 4.2.0)
factory_bot_rails (5.1.0)
factory_bot (~> 5.1.0)
railties (>= 4.2.0)
ffi (1.11.1)
font-awesome-sass (5.11.2)
sassc (>= 1.11)
friendly_id (5.2.5)
friendly_id (5.1.0)
activerecord (>= 4.0.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
haml (5.1.2)
haml (5.1.1)
temple (>= 0.8.0)
tilt
i18n (1.6.0)
Expand All @@ -95,30 +86,24 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.7.0)
launchy (~> 2.2)
loofah (2.2.3)
loofah (2.3.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.2)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.12.0)
nio4r (2.5.1)
minitest (5.12.2)
nio4r (2.5.2)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
pg (1.1.4)
popper_js (1.14.5)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.1)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand All @@ -134,6 +119,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.1.7)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -145,7 +134,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.3)
rake (13.0.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
Expand All @@ -163,25 +152,19 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
sassc (2.2.1)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.8.2)
temple (0.8.1)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
tilt (2.0.8)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
Expand All @@ -192,21 +175,20 @@ PLATFORMS
ruby

DEPENDENCIES
bootstrap (~> 4.3.1)
byebug
database_cleaner
dynamic_forms!
factory_bot_rails
font-awesome-sass (~> 5.11.2)
friendly_id (~> 5.2.4)
friendly_id (~> 5.1.0)
haml
jquery-rails
kaminari
letter_opener
pg
pry
pry-rails
rails-controller-testing
rspec-rails
shoulda-matchers

BUNDLED WITH
1.16.2
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'


Expand All @@ -27,8 +27,8 @@ require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << 'spec'
t.pattern = 'spec/**/*_test.rb'
t.verbose = false
end

Expand Down
2 changes: 0 additions & 2 deletions app/assets/javascripts/dynamic_forms/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@
//= require_tree .
//= require jquery3
//= require jquery_ujs
//= require popper
//= require bootstrap-sprockets
1 change: 1 addition & 0 deletions app/assets/stylesheets/dynamic_forms/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 0 additions & 3 deletions app/assets/stylesheets/dynamic_forms/application.scss

This file was deleted.

15 changes: 15 additions & 0 deletions app/controllers/dynamic_forms/api/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module DynamicForms
module Api
class BaseController < ActionController::Base
before_action :set_cors

private
def set_cors
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
end
end
end
7 changes: 3 additions & 4 deletions app/controllers/dynamic_forms/api/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

module DynamicForms
module Api
class FormController < ApplicationController
class FormController < DynamicForms::Api::BaseController
UNECESSARY_PARAMS = %w[action controller uuid]

skip_before_action :verify_authenticity_token
before_action :honey_pot, only: [:create]
before_action :set_custom_form
before_action :validations
Expand Down Expand Up @@ -40,9 +39,9 @@ def honey_pot

def validations
return render json: {}, status: :not_found unless @custom_form.enabled
return unless @custom_form.restrict_domian.present?
return unless @custom_form.restrict_domain.present?

if request.domain != @custom_form.restrict_domian
unless request.domain == @custom_form.restrict_domain
return render json: {}, status: :unauthorized
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/dynamic_forms/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module DynamicForms
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
class ApplicationController < ::ApplicationController
include ApplicationHelper
if DynamicForms.layout
layout DynamicForms.layout
end
end
end
10 changes: 5 additions & 5 deletions app/controllers/dynamic_forms/custom_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require_dependency "dynamic_forms/application_controller"

module DynamicForms
class CustomFormsController < ApplicationController
class CustomFormsController < DynamicForms::ApplicationController
before_action :load_custom_form, only: %w[edit update destroy show]

def index
@custom_forms = CustomForm.page(params[:page]).per(10)
@custom_forms = CustomForm.page(params[:page])
render :index
end

def show; end

def new
@custom_form = CustomForm.new
end
Expand Down Expand Up @@ -50,7 +50,7 @@ def destroy
def custom_forms_params
params.require(:custom_form).permit(
:name,
:restrict_domian,
:restrict_domain,
:target_email,
:enabled,
:allow_notifications,
Expand Down
25 changes: 18 additions & 7 deletions app/controllers/dynamic_forms/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
require_dependency "dynamic_forms/application_controller"

module DynamicForms
class SubmissionsController < ApplicationController
class SubmissionsController < DynamicForms::ApplicationController
before_action :load_custom_form
before_action :load_submission, only: %w[destroy]
before_action :load_submission, only: %i[destroy]
before_action :load_submissions, only: %i[index export]

def index
@submissions = @custom_form.submissions
.order('created_at DESC')
.page(params[:page])
.per(10)
respond_to do |format|
format.html
format.csv {
send_data SubmissionExporter.for(@submissions, 'csv'),
filename: "submissions-#{Date.today}.csv"
}
end
end

def destroy
if @submission.destroy
flash[:success] = "Submission was successfully destroyed"
else
flash[:error] = "Submission couldn't be destroyed, try again"
flash[:error] = "Submission couldn't be destroyed, try again"
end
redirect_to custom_form_submissions_path(@custom_form)
end


private

def load_custom_form
Expand All @@ -30,6 +35,12 @@ def load_custom_form
redirect_to custom_forms_path
end

def load_submissions
@submissions = @custom_form.submissions
.order('created_at DESC')
.page(params[:page])
end

def load_submission
@submission = @custom_form.submissions.find(params[:id])
rescue
Expand Down
Loading