diff options
| author | Robert | 2017-04-19 17:41:44 +0200 |
|---|---|---|
| committer | Robert | 2017-04-19 17:41:44 +0200 |
| commit | b767e3c006e9eeee22e2de939605203d8cb99f32 (patch) | |
| tree | 7a7fec578f4117312d2bc4007f7e9d9af57dcb73 | |
| parent | d9fbb75454e7c2b83bb0d7ef06b301f1950cf130 (diff) | |
| parent | e0fd60242c3994b4157d506c1ce71cab6ffab268 (diff) | |
| download | chouette-core-b767e3c006e9eeee22e2de939605203d8cb99f32.tar.bz2 | |
Merge branch 'master' of github.com:af83/stif-boiv
23 files changed, 224 insertions, 52 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index 1a6b7d197..a023360a5 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -68,6 +68,18 @@ const actions = { var date = new Date(strDate) return monthList[date.getMonth()] }, + getHumanDate(strDate, mLimit) { + let origin = strDate.split('-') + let D = origin[2] + let M = actions.monthName(strDate).toLowerCase() + let Y = origin[0] + + if(mLimit) { + M = M.substr(0, mLimit) + '.' + } + + return (D + ' ' + M + ' ' + Y) + }, updateSynthesis: (state, daytypes) => { let periods = state.time_table_periods diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/DayTypesInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js index 560ff198b..cc1e34c52 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/DayTypesInDay.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js @@ -2,7 +2,7 @@ var React = require('react') var Component = require('react').Component var PropTypes = require('react').PropTypes -class DayTypesInDay extends Component { +class ExceptionsInDay extends Component { constructor(props) { super(props) } @@ -15,9 +15,9 @@ class DayTypesInDay extends Component { } } -DayTypesInDay.propTypes = { +ExceptionsInDay.propTypes = { value: PropTypes.object.isRequired, index: PropTypes.number.isRequired } -module.exports = DayTypesInDay +module.exports = ExceptionsInDay diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js new file mode 100644 index 000000000..61098d9ea --- /dev/null +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js @@ -0,0 +1,27 @@ +var React = require('react') +var Component = require('react').Component +var PropTypes = require('react').PropTypes +var actions = require('../actions') + +class PeriodManager extends Component { + constructor(props) { + super(props) + } + + render() { + return ( + <div + className='period_manager' + id={this.props.value.id} + > + <strong>{(this.props.value.period_start.split('-')[2]) + ' > ' + actions.getHumanDate(this.props.value.period_end, 3)}</strong> + </div> + ) + } +} + +PeriodManager.propTypes = { + value: PropTypes.object.isRequired +} + +module.exports = PeriodManager diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js new file mode 100644 index 000000000..adc500c86 --- /dev/null +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js @@ -0,0 +1,67 @@ +var React = require('react') +var Component = require('react').Component +var PropTypes = require('react').PropTypes +var PeriodManager = require('./PeriodManager') + +class PeriodsInDay extends Component { + constructor(props) { + super(props) + } + + isIn(date) { + let currentDate = date.getTime() + let cls = 'td' + let periods = this.props.value + + periods.map((p, i) => { + let begin = new Date(p.period_start).getTime() + let end = new Date(p.period_end).getTime() + + if(currentDate >= begin && currentDate <= end) { + if(currentDate == begin) { + cls += ' in_periods start_period' + } else if(currentDate == end) { + cls += ' in_periods end_period' + } else { + cls += ' in_periods' + } + } + }) + return cls + } + + render() { + return ( + <div + className={this.isIn(this.props.currentDate)} + > + {this.props.value.map((p, i) => { + let begin = new Date(p.period_start).getTime() + let end = new Date(p.period_end).getTime() + let d = this.props.currentDate.getTime() + + if(d >= begin && d <= end) { + if(d == begin) { + return ( + <PeriodManager + key={i} + value={p} + /> + ) + } else { + return false + } + } + })} + </div> + ) + } +} + +PeriodsInDay.propTypes = { + value: PropTypes.array.isRequired, + currentDate: PropTypes.object.isRequired, + index: PropTypes.number.isRequired +} + +module.exports = PeriodsInDay diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js index 715f3ec3b..b27dddbf1 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js @@ -2,7 +2,8 @@ var React = require('react') var Component = require('react').Component var PropTypes = require('react').PropTypes var TimeTableDay = require('./TimeTableDay') -var DayTypesInDay = require('./DayTypesInDay') +var PeriodsInDay = require('./PeriodsInDay') +var ExceptionsInDay = require('./ExceptionsInDay') var actions = require('../actions') class Timetable extends Component{ @@ -10,6 +11,14 @@ class Timetable extends Component{ super(props) } + currentDate(mFirstday, day) { + let currentMonth = mFirstday.split('-') + let twodigitsDay = day < 10 ? ('0' + day) : day + let currentDate = new Date(currentMonth[0] + '-' + currentMonth[1] + '-' + twodigitsDay) + + return currentDate + } + componentDidUpdate(prevProps, prevState) { if(this.props.status.isFetching == false){ $('.table-2entries').each(function() { @@ -67,10 +76,21 @@ class Timetable extends Component{ key={i} className={'td-group' + (this.props.metas.day_types[d.wday] ? '' : ' out_from_daytypes') + (d.wday == 0 ? ' last_wday' : '')} > - <DayTypesInDay + {/* day_types */} + <div className="td"></div> + + {/* periods */} + <PeriodsInDay + index={i} + value={this.props.timetable.time_table_periods} + currentDate={this.currentDate(this.props.timetable.current_periode_range, d.mday)} + /> + + {/* exceptions */} + <ExceptionsInDay index={i} value={this.props.timetable} - /> + /> </div> )} </div> diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index 0803f6210..bc04b49e3 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -268,6 +268,7 @@ // TD group > .td-group display: inline-block + vertical-align: top > .td display: block diff --git a/app/assets/stylesheets/modules/_timetables.sass b/app/assets/stylesheets/modules/_timetables.sass index 4dcb78b0e..e44a254c5 100644 --- a/app/assets/stylesheets/modules/_timetables.sass +++ b/app/assets/stylesheets/modules/_timetables.sass @@ -59,17 +59,38 @@ background-color: transparent &.included - background-color: $gold + background-color: rgba($gold, 0.7) > .td-group width: 34px - border-right: 1px solid rgba($grey, 0.5) + > .td + border-right: 1px solid rgba($grey, 0.5) &.last_wday - &:not(:last-child) + &:not(:last-child) > .td border-right: 2px solid $darkgrey &.out_from_daytypes - > .td - background-image: linear-gradient(45deg, rgba($grey, 0.15) 0%, rgba($grey, 0.15) 49%, rgba($grey, 0.5) 50%, rgba($grey, 0.15) 51%, rgba($grey, 0.15) 99%, rgba($grey, 0.15) 100%) - background-size: 25px 25px + background-image: linear-gradient(45deg, rgba($grey, 0.15) 0%, rgba($grey, 0.15) 49%, rgba($grey, 0.5) 50%, rgba($grey, 0.15) 51%, rgba($grey, 0.15) 99%, rgba($grey, 0.15) 100%) + background-size: 25px 25px + + > .td + &.in_periods + background-color: rgba($gold, 0.7) + border-left-color: rgba($gold, 0.7) + border-right-color: rgba($gold, 0.7) + + &.start_period + border-left-color: rgba($grey, 0.5) + &.end_period + border-right-color: rgba($grey, 0.5) + + .period_manager + display: block + height: auto + word-wrap: normal + white-space: nowrap + position: absolute + left: 8px + top: 6px + z-index: 5 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c2414f5bb..2bdf8078a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,6 +15,10 @@ class ApplicationController < ActionController::Base I18n.locale = session[:language] || I18n.default_locale end + def pundit_user + UserContext.new(current_user, referential: self.try(:current_referential)) + end + protected def user_not_authorized diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index 7bc048731..c42aa785b 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -1,7 +1,6 @@ class LineFootnotesController < BreadcrumbController defaults :resource_class => Chouette::Line include PolicyChecker - before_action :check_policy, only: [:edit, :update, :destroy] respond_to :json, :only => :show belongs_to :referential @@ -27,7 +26,6 @@ class LineFootnotesController < BreadcrumbController end protected - # overrides default def check_policy authorize resource, "#{action_name}_footnote?".to_sym diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index d45f4d1af..c084b592a 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -1,6 +1,5 @@ class VehicleJourneysController < ChouetteController defaults :resource_class => Chouette::VehicleJourney - before_action :check_policy, only: [:edit, :update, :destroy] before_action :user_permissions, only: :index respond_to :json, :only => :index @@ -130,17 +129,12 @@ class VehicleJourneysController < ChouetteController @matrix = resource_class.matrix(@vehicle_journeys) end - def check_policy - authorize resource - end - def user_permissions @perms = {}.tap do |perm| ['vehicle_journeys.create', 'vehicle_journeys.edit', 'vehicle_journeys.destroy'].each do |name| - perm[name] = current_user.permissions.include?(name) + perm[name] = policy(:vehicle_journey).send("#{name.split('.').last}?") end - end - @perms = @perms.to_json + end.to_json end private diff --git a/app/models/user_context.rb b/app/models/user_context.rb new file mode 100644 index 000000000..e0a856e4b --- /dev/null +++ b/app/models/user_context.rb @@ -0,0 +1,8 @@ +class UserContext + attr_reader :user, :context + + def initialize(user, context = {}) + @user = user + @context = context + end +end diff --git a/app/policies/acces_point_policy.rb b/app/policies/acces_point_policy.rb index 4f604693c..904b7a242 100644 --- a/app/policies/acces_point_policy.rb +++ b/app/policies/acces_point_policy.rb @@ -10,11 +10,11 @@ class AccessPointPolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('access_points.edit') + organisation_match? && user.has_permission?('access_points.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('access_points.destroy') + organisation_match? && user.has_permission?('access_points.destroy') end def update? ; edit? end diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb index 8e7a86490..73b2d1baa 100644 --- a/app/policies/access_link_policy.rb +++ b/app/policies/access_link_policy.rb @@ -10,11 +10,11 @@ class AccessLinkPolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('access_links.edit') + organisation_match? && user.has_permission?('access_links.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('access_links.destroy') + organisation_match? && user.has_permission?('access_links.destroy') end def update? ; edit? end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 07138b38e..4a2d760fb 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,11 +1,21 @@ class ApplicationPolicy attr_reader :user, :record - def initialize(user, record) - @user = user + def initialize(user_context, record) + @user = user_context.user + @referential = user_context.context[:referential] @record = record end + attr_accessor :referential + def referential + @referential ||= record_referential + end + + def record_referential + record.referential if record.respond_to?(:referential) + end + def index? false end @@ -38,8 +48,14 @@ class ApplicationPolicy Pundit.policy_scope!(user, record.class) end - def organisation_match?(via_referential: false) - eval("user.organisation == record#{'.referential' if via_referential}.organisation") + def organisation_match? + user.organisation == organisation + end + + def organisation + # When sending permission to react UI, we don't have access to record object for edit & destroy.. actions + organisation = record.is_a?(Symbol) ? nil : record.try(:organisation) + organisation or referential.try :organisation end class Scope diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb index cc49f575f..abefd741c 100644 --- a/app/policies/connection_link_policy.rb +++ b/app/policies/connection_link_policy.rb @@ -10,11 +10,11 @@ class ConnectionLinkPolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('connection_links.edit') + organisation_match? && user.has_permission?('connection_links.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('connection_links.destroy') + organisation_match? && user.has_permission?('connection_links.destroy') end def update? ; edit? end diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb index 2b5e4c6cd..56f32613c 100644 --- a/app/policies/journey_pattern_policy.rb +++ b/app/policies/journey_pattern_policy.rb @@ -11,15 +11,11 @@ class JourneyPatternPolicy < ApplicationPolicy end def edit? - # In React UI, we don't have access to record object yet. - # In this case record is a symbol - can_edit = user.has_permission?('journey_patterns.edit') - record.is_a?(Symbol) ? can_edit : (organisation_match?(via_referential: true) && can_edit) + organisation_match? && user.has_permission?('journey_patterns.edit') end def destroy? - can_destroy = user.has_permission?('journey_patterns.destroy') - record.is_a?(Symbol) ? can_destroy : (organisation_match?(via_referential: true) && can_destroy) + organisation_match? && user.has_permission?('journey_patterns.destroy') end def update? ; edit? end diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb index fb55f006a..8d366aff7 100644 --- a/app/policies/referential_policy.rb +++ b/app/policies/referential_policy.rb @@ -10,21 +10,24 @@ class ReferentialPolicy < ApplicationPolicy end def edit? - user.has_permission?('referentials.edit') + organisation_match? && user.has_permission?('referentials.edit') end def destroy? - user.has_permission?('referentials.destroy') + organisation_match? && user.has_permission?('referentials.destroy') end def archive? edit? end + def clone? + organisation_match? && create? + end + def unarchive? ; archive? end def update? ; edit? end def new? ; create? end - def clone? ; create? end end diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb index 0f42b7f08..c4d048f2a 100644 --- a/app/policies/route_policy.rb +++ b/app/policies/route_policy.rb @@ -10,11 +10,11 @@ class RoutePolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('routes.edit') + organisation_match? && user.has_permission?('routes.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('routes.destroy') + organisation_match? && user.has_permission?('routes.destroy') end def update? ; edit? end diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb index fbf322066..3126241f0 100644 --- a/app/policies/routing_constraint_zone_policy.rb +++ b/app/policies/routing_constraint_zone_policy.rb @@ -10,11 +10,11 @@ class RoutingConstraintZonePolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('routing_constraint_zones.edit') + organisation_match? && user.has_permission?('routing_constraint_zones.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('routing_constraint_zones.destroy') + organisation_match? && user.has_permission?('routing_constraint_zones.destroy') end def update? ; edit? end diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb index 1d14c646a..6ca02f451 100644 --- a/app/policies/time_table_policy.rb +++ b/app/policies/time_table_policy.rb @@ -10,11 +10,11 @@ class TimeTablePolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('time_tables.edit') + organisation_match? && user.has_permission?('time_tables.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('time_tables.destroy') + organisation_match? && user.has_permission?('time_tables.destroy') end def update? ; edit? end diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb index 785c2bb1f..ae3680adf 100644 --- a/app/policies/vehicle_journey_policy.rb +++ b/app/policies/vehicle_journey_policy.rb @@ -10,11 +10,11 @@ class VehicleJourneyPolicy < ApplicationPolicy end def edit? - organisation_match?(via_referential: true) && user.has_permission?('vehicle_journeys.edit') + organisation_match? && user.has_permission?('vehicle_journeys.edit') end def destroy? - organisation_match?(via_referential: true) && user.has_permission?('vehicle_journeys.destroy') + organisation_match? && user.has_permission?('vehicle_journeys.destroy') end def update? ; edit? end diff --git a/app/views/time_tables/month.rabl b/app/views/time_tables/month.rabl index 571abfb0c..5b8b67f6c 100644 --- a/app/views/time_tables/month.rabl +++ b/app/views/time_tables/month.rabl @@ -1,4 +1,9 @@ object @time_table -node(:name) { I18n.l(@date, format: '%B') } -node(:days) {|tt| tt.month_inspect(@date) } +node do |tt| + { + name: I18n.l(@date, format: '%B'), + days: tt.month_inspect(@date), + day_types: %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| tt.send(d) }.map{ |d| tt.human_attribute_name(d).first(2)}.join('') + } +end diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index f9a705c29..b46cf09a4 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -8,7 +8,7 @@ .row.mb-sm .col-lg-12.text-right - if policy(Referential).create? - = link_to t('referentials.actions.new'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary' + = link_to t('referentials.actions.new'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary' / PageContent .page_content |
