Skip to content

Commit

Permalink
Merge pull request #191 from fsek/cafe-quick-fix
Browse files Browse the repository at this point in the history
Reworked CafeWork-module
  • Loading branch information
davidwessman committed May 17, 2015
2 parents 98d6852 + 190472d commit a5a83e9
Show file tree
Hide file tree
Showing 48 changed files with 654 additions and 549 deletions.
36 changes: 33 additions & 3 deletions app/controllers/admin/cafe_works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Admin::CafeWorksController < ApplicationController
before_action :set_cafe_setup, only: [:setup_create]

def show
@councils = Council.all
end

def edit
end

def new
Expand All @@ -15,6 +19,10 @@ def new
def edit
end

def overview
@cafe_works = CafeWork.all_work_day
end

def create
flash[:notice] = alert_create(CafeWork) if @cafe_work.save
redirect_to [:admin, @cafe_work]
Expand All @@ -33,14 +41,32 @@ def destroy
@id = @cafe_work.id
@cafe_work.destroy
respond_to do |format|
format.html { redirect_to :admin_hilbert, alert: alert_destroy(CafeWork) }
format.html { redirect_to admin_cafe_works_path, alert: alert_destroy(CafeWork) }
format.js
end
end

def add_worker
if @cafe_work.update(worker_params)
redirect_to admin_cafe_work_path(@cafe_work), notice: I18n.t('cafe_work.worker_added')
else
render action: :show
end
end

def update_worker
if @cafe_work.update!(worker_params)
redirect_to cafe_work_path([:admin, @cafe_work]), notice: I18n.t('cafe_work.worker_updated')
else
render action: :show
end
end

def remove_worker
if !@cafe_work.clear_worker
render action: show, notice: 'Lyckades inte'
else
redirect_to admin_cafe_work_path(@cafe_work)
end
end

Expand Down Expand Up @@ -71,7 +97,11 @@ def authorize
end

def cafe_work_params
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv, :lv_first, :lv_last, :d_year)
params.require(:cafe_work).permit(:work_day, :pass, :lp, :lv, :lv_last, :d_year)
end

def worker_params
params.require(:cafe_work).permit(:user_id, :utskottskamp, council_ids: [])
end

def set_new_cafe_work
Expand All @@ -89,7 +119,7 @@ def set_cafe_setup
end

def set_lv
@lv_first = cafe_work_params[:lv_first] || 0
@lv_first = cafe_work_params[:lv] || 0
@lv_last = cafe_work_params[:lv_last] || 0
end

Expand Down
39 changes: 28 additions & 11 deletions app/controllers/cafe_works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,38 @@ class CafeWorksController < ApplicationController
before_action :set_faqs, only: :index

def show
@cafe_work.load(current_user)
if @cafe_work.user.present?
@user = @cafe_work.user
else
@user = current_user
@form = true
end
@cafe_work.valid?
end

def edit
end

def add_worker
if @cafe_work.add_worker(worker_params, current_user)
redirect_to cafe_work_path(@cafe_work), notice: I18n.t('cafe_work.worker_added')
else
@form = true
render action: :show
end
end

def update_worker
if @cafe_work.add_or_update(worker_params, current_user)
flash[:notice] = 'Bokningen uppdaterades - du arbetar!'
redirect_to @cafe_work
if @cafe_work.update_worker(worker_params, current_user)
redirect_to cafe_work_path(@cafe_work), notice: I18n.t('cafe_work.worker_updated')
else
render action: :show
end
end

def remove_worker
if @cafe_work.remove_worker(current_user)
flash[:notice] = 'Du arbetar inte längre på passet'
redirect_to @cafe_work
redirect_to cafe_work_path(@cafe_work), notice: I18n.t('cafe_work.worker_removed')
else
render action: :show
end
Expand All @@ -29,22 +45,23 @@ def remove_worker
def index
respond_to do |format|
format.html { @lv = CafeWork.get_lv }
format.json { render json: CafeWork.between(params[:start], params[:end]) }
format.json do
render json: CafeWork.between(params[:start],
params[:end]).as_json(user: current_user)
end
end
end

def nyckelpiga
authorize! :nyckelpiga, CafeWork
@date = (params[:date].present?) ? Time.zone.parse(params[:date]) : Time.zone.now
@work_grid = initialize_grid(CafeWork.between(@date.beginning_of_day,
@date.end_of_day).ascending)
@cafe_works = CafeWork.between(@date.beginning_of_day, @date.end_of_day).ascending
end

private

def worker_params
params.require(:cafe_work).permit(:user_id, :firstname, :lastname, :phone, :email,
:utskottskamp, council_ids: [])
params.require(:cafe_work).permit(:user_id, :utskottskamp, council_ids: [])
end

def councils
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
class UsersController < ApplicationController
load_permissions_and_authorize_resource
before_action :set_user

def index
end

def show
end

def profile
end

def edit
if @tab.nil?
@tab = :profile
Expand Down
11 changes: 4 additions & 7 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ def initialize(user)

# For calendar-subscription
can :export, Event
# Leaking personal information!
# can :read, CafeWork
can :read, CafeWork
can :main, Rent
can [:new, :read, :create], Faq

# Abilities all signed in users get
if user.id
can [:main, :new, :edit, :create, :update, :destroy], Rent, user_id: user.id
can [:edit, :update, :show, :update_password, :update_account], User, id: user.id
# TODO Implement add_worker
# can :add_worker, CafeWork, user_id: nil
# can :update_worker, CafeWork, user_id: user.id
# can :update_worker, CafeWork
# can :remove_worker, CafeWork, user_id: user.id
can :add_worker, CafeWork, user_id: nil
can [:edit, :update_worker, :remove_worker], CafeWork, user_id: user.id
can [:show, :avatar], User
can [:read, :display, :hide], Post
end
Expand Down
Loading

0 comments on commit a5a83e9

Please sign in to comment.