aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/calendars_controller.rb
diff options
context:
space:
mode:
authorcedricnjanga2018-01-24 19:55:56 -0800
committercedricnjanga2018-01-24 19:55:56 -0800
commitf32d869cc3f34a939764cc3fa4d612a5d6544d08 (patch)
tree87d5a6b4f589a39e038451e3dd6290ba975f7986 /app/controllers/calendars_controller.rb
parent0f59b9c1d0133393f68194a366aafc27ca23392b (diff)
downloadchouette-core-f32d869cc3f34a939764cc3fa4d612a5d6544d08.tar.bz2
update calendar build_links for table builder
Diffstat (limited to 'app/controllers/calendars_controller.rb')
-rw-r--r--app/controllers/calendars_controller.rb25
1 files changed, 19 insertions, 6 deletions
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])