From f32d869cc3f34a939764cc3fa4d612a5d6544d08 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 24 Jan 2018 19:55:56 -0800 Subject: update calendar build_links for table builder --- app/controllers/calendars_controller.rb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'app/controllers/calendars_controller.rb') diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 72d213953..27c944f5f 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,4 +1,5 @@ class CalendarsController < ChouetteController + include WorkgroupSupport include PolicyChecker defaults resource_class: Calendar before_action :ransack_contains_date, only: [:index] @@ -7,19 +8,30 @@ class CalendarsController < ChouetteController def index index! do - @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator, context: { - workgroup: current_workgroup - }) + @calendars = decorate_calendars(@calendars) end end def show show! do - @calendar = @calendar.decorate + @calendar = @calendar.decorate(context: { + workgroup: current_workgroup + }) end end private + + def decorate_calendars(calendars) + ModelDecorator.decorate( + calendars, + with: CalendarDecorator, + context: { + workgroup: current_workgroup + } + ) + end + def calendar_params permitted_params = [:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]] permitted_params << :shared if policy(Calendar).share? @@ -36,18 +48,19 @@ class CalendarsController < ChouetteController protected def resource - @calendar = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).find_by_id(params[:id]) + @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id) end def build_resource super.tap do |calendar| + calendar.workgroup = current_workgroup calendar.organisation = current_organisation end end def collection return @calendars if @calendars - scope = Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id) scope = shared_scope(scope) @q = scope.ransack(params[:q]) -- cgit v1.2.3