Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implementation permissions using cancancan gem #5

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,18 @@ group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]
# gem 'bootstrap-sass'
# gem 'bootstrap', '~> 4.4.1'
gem 'bootstrap-sass'
gem 'font-awesome-rails'
gem 'popper_js', '~> 1.12.3'
# gem 'dragula-rails'
gem 'ffi', '~> 1.9', '>= 1.9.10'
gem 'pry', '~> 0.10.3'
gem "font-awesome-sass", "~> 6.2.1"

gem "spring"
gem "spring-commands-rspec"
gem 'ransack'
gem 'kaminari', '~> 0.15.0'
gem 'rubocop-rails', require: false
gem 'paperclip', '~> 3.5'
gem 'remotipart', '~> 1.2'
gem 'friendly_numbers'
gem 'cancancan', '~> 1.17'
59 changes: 57 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.2)
ast (2.4.2)
autoprefixer-rails (9.8.6)
execjs
bcrypt (3.1.18)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
builder (3.1.4)
cancancan (1.17.0)
climate_control (0.2.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.3)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
Expand All @@ -41,7 +46,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.0)
devise (3.5.10)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -56,22 +61,38 @@ GEM
railties (>= 3.2, < 8.0)
font-awesome-sass (6.2.1)
sassc (~> 2.0)
friendly_numbers (0.6.0)
hike (1.2.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
jbuilder (1.5.3)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-rails (3.1.5)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
kaminari (0.15.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.8.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
minitest (4.7.5)
multi_json (1.15.0)
orm_adapter (0.5.0)
paperclip (3.5.4)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
parallel (1.19.2)
parser (3.2.0.0)
ast (~> 2.4.1)
popper_js (1.12.9)
pry (0.10.4)
coderay (~> 1.1.0)
Expand All @@ -93,10 +114,31 @@ GEM
activesupport (= 4.0.13)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.1.1)
rake (13.0.6)
ransack (1.8.10)
actionpack (>= 3.0, < 5.2)
activerecord (>= 3.0, < 5.2)
activesupport (>= 3.0, < 5.2)
i18n
rdoc (6.2.0)
remotipart (1.4.4)
responders (1.1.2)
railties (>= 3.2, < 4.2)
rexml (3.2.5)
rubocop (0.81.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
rexml
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-rails (2.5.2)
activesupport
rack (>= 1.1)
rubocop (>= 0.72.0)
ruby-progressbar (1.11.0)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
Expand All @@ -105,9 +147,12 @@ GEM
sprockets-rails (~> 2.0)
sassc (2.4.0)
ffi (~> 1.9)
sdoc (2.5.0)
sdoc (2.6.0)
rdoc (>= 5.0)
slop (3.6.0)
spring (1.7.2)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (2.12.5)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -127,6 +172,7 @@ GEM
tzinfo (0.3.61)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.8.0)
warden (1.2.7)
rack (>= 1.0)

Expand All @@ -136,19 +182,28 @@ PLATFORMS
DEPENDENCIES
bcrypt
bootstrap-sass
cancancan (~> 1.17)
coffee-rails (~> 4.0.0)
devise
ffi (~> 1.9, >= 1.9.10)
font-awesome-rails
font-awesome-sass (~> 6.2.1)
friendly_numbers
jbuilder (~> 1.2)
jquery-rails
kaminari (~> 0.15.0)
paperclip (~> 3.5)
popper_js (~> 1.12.3)
pry (~> 0.10.3)
rails (= 4.0.13)
ransack
remotipart (~> 1.2)
rubocop-rails
sass-rails (~> 4.0.2)
sassc (~> 2.4.0)
sdoc
spring
spring-commands-rspec
sqlite3 (~> 1.3.13)
thor (= 0.19.1)
turbolinks
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//= require jquery
//= require jquery_ujs
//= require popper
//= require turbolinks
//* require tree .
//= require custom

//= require jquery.remotipart
7 changes: 7 additions & 0 deletions app/assets/stylesheets/documents.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Place all the styles related to the documents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.me-3 {
margin-right: 1.5rem!important;
}
12 changes: 9 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

before_filter :set_global_search_variable

def set_global_search_variable
@q = Task.search(params[:q])
end
rescue_from CanCan::AccessDenied do
flash[:error] = 'Access denied!'
redirect_to root_url
end
end
75 changes: 41 additions & 34 deletions app/controllers/board_sections_controller.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
class BoardSectionsController < ApplicationController
before_action :set_board_section_object, :only=>[:show,:edit,:update,:delete]
before_action :set_board
before_action :set_board_section_object, only: %i[show edit update delete]
before_action :set_board

def index
@board_sections = BoardSection.all
end
def new
@board_section = @board.board_sections.build
end
def show
end
def create
@board_section = @board.board_sections.build(board_section_params)
def index
@board_sections = BoardSection.all
end

def new
@board_section = @board.board_sections.build
end

def show; end

def create
@board_section = @board.board_sections.build(board_section_params)
respond_to do |format|
if @board_section.save
redirect_to request.referer
format.js
format.html { redirect_to request.referer }
else
render :new
end
end
def edit
end
def update
if @board_section.update(board_section_params)
redirect_to @board_section
else
render :edit
end
end
def delete
@board_section.destroy
end

def edit; end

def update
if @board_section.update(board_section_params)
redirect_to @board_section
else
render :edit
end
end

private
def set_board
@board = Board.find(params[:board_id])
end
def set_board_section_object
@board_section = BoardSection.find(params[:id])
end
def board_section_params
params.require(:board_section).permit(:id, :name, :board_type)
end
def delete; end

private

def set_board
@board = Board.find(params[:board_id])
end

def set_board_section_object
@board_section = BoardSection.find(params[:id])
end

def board_section_params
params.require(:board_section).permit(:id, :name, :board_type)
end
end
46 changes: 29 additions & 17 deletions app/controllers/boards_controller.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
class BoardsController < ApplicationController
before_action :set_board_object, :only=> [:show,:edit,:update,:destroy]
before_action :set_board_object, only: %i[show edit update destroy]

def index
@boards = Board.all
@boards = Board.all.page(params[:page])
end

def new
@board = Board.new()
@board = Board.new
end

def show
@board_sections = @board.board_sections
end

def create
@board = Board.new(board_params)
if @board.save
redirect_to root_path
else
render :new
respond_to do |format|
if @board.save
format.html { redirect_to root_path }
format.js
else
render :new
end
end
end
def edit
end

def edit; end

def update
if @board.update(board_params)
redirect_to @board
else
render :edit
end
end

def destroy
@board.destroy
redirect_to @board
respond_to do |format|
format.js { render layout: false }
format.html { redirect_to @board }
end
end

private
def board_params
params.require(:board).permit(:id, :name, :board_type,:board_section_is)
end
def set_board_object
@board = Board.find(params[:id])
end

def board_params
params.require(:board).permit(:id, :name, :board_type, :board_section_id)
end

def set_board_object
@board = Board.find(params[:id])
end
end
Loading