aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEVNOTES.md2
-rw-r--r--app/controllers/vehicle_journeys_controller.rb25
-rw-r--r--app/helpers/newapplication_helper.rb3
-rw-r--r--app/javascript/journey_patterns/components/JourneyPattern.js4
-rw-r--r--app/javascript/packs/vehicle_journeys/index.js3
-rw-r--r--app/javascript/vehicle_journeys/actions/index.js1
-rw-r--r--app/javascript/vehicle_journeys/components/Filters.js3
-rw-r--r--app/javascript/vehicle_journeys/components/tools/CreateModal.js6
-rw-r--r--app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js8
-rw-r--r--app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js136
-rw-r--r--app/javascript/vehicle_journeys/containers/Filters.js3
-rw-r--r--app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js1
-rw-r--r--app/javascript/vehicle_journeys/reducers/index.js4
-rw-r--r--app/javascript/vehicle_journeys/reducers/missions.js6
-rw-r--r--app/javascript/vehicle_journeys/reducers/modal.js3
-rw-r--r--app/models/calendar.rb2
-rw-r--r--app/models/chouette/vehicle_journey.rb8
-rw-r--r--app/models/compliance_check_set.rb2
-rw-r--r--app/models/compliance_control_set.rb2
-rw-r--r--app/models/concerns/objectid_support.rb5
-rw-r--r--app/models/custom_field.rb7
-rw-r--r--app/models/merge.rb32
-rw-r--r--app/models/public_version.rb4
-rw-r--r--app/models/referential.rb15
-rw-r--r--app/models/workbench.rb1
-rw-r--r--app/models/workgroup.rb14
-rw-r--r--app/policies/access_link_policy.rb6
-rw-r--r--app/policies/access_point_policy.rb6
-rw-r--r--app/policies/application_policy.rb14
-rw-r--r--app/policies/connection_link_policy.rb6
-rw-r--r--app/policies/journey_pattern_policy.rb6
-rw-r--r--app/policies/line_policy.rb6
-rw-r--r--app/policies/purchase_window_policy.rb8
-rw-r--r--app/policies/referential_policy.rb10
-rw-r--r--app/policies/route_policy.rb6
-rw-r--r--app/policies/routing_constraint_zone_policy.rb6
-rw-r--r--app/policies/time_table_combination_policy.rb2
-rw-r--r--app/policies/time_table_policy.rb10
-rw-r--r--app/policies/vehicle_journey_policy.rb6
-rw-r--r--app/views/merges/show.html.slim6
-rw-r--r--app/views/referentials/show.html.slim6
-rw-r--r--app/views/vehicle_journeys/index.html.slim1
-rw-r--r--app/views/workbenches/show.html.slim2
-rw-r--r--config/initializers/apartment.rb4
-rw-r--r--config/initializers/stif.rb15
-rw-r--r--db/migrate/20180108132310_create_workgroups.rb11
-rw-r--r--db/migrate/20180109133022_add_workgroup_id_to_workbenches.rb6
-rw-r--r--db/migrate/20180109144120_create_custom_fields.rb14
-rw-r--r--db/migrate/20180109173815_add_index_resource_type_on_custom_fields.rb5
-rw-r--r--db/migrate/20180109180350_add_custom_field_values_to_vehicle_journeys.rb5
-rw-r--r--db/schema.rb30
-rw-r--r--db/seeds/stif.seeds.rb7
-rw-r--r--spec/factories/custom_fields.rb9
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/factories/workgroups.rb7
-rw-r--r--spec/helpers/table_builder_helper_spec.rb3
-rw-r--r--spec/javascript/vehicle_journeys/actions_spec.js2
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb5
-rw-r--r--spec/models/custom_field_spec.rb27
-rw-r--r--spec/models/referential_spec.rb38
-rw-r--r--spec/models/workbench_spec.rb1
-rw-r--r--spec/models/workgroup_spec.rb30
-rw-r--r--spec/policies/access_link_policy_spec.rb10
-rw-r--r--spec/policies/access_point_policy_spec.rb10
-rw-r--r--spec/policies/company_policy_spec.rb5
-rw-r--r--spec/policies/connection_link_policy_spec.rb10
-rw-r--r--spec/policies/group_of_line_policy_spec.rb14
-rw-r--r--spec/policies/journey_pattern_policy_spec.rb10
-rw-r--r--spec/policies/line_policy_spec.rb11
-rw-r--r--spec/policies/network_policy_spec.rb14
-rw-r--r--spec/policies/purchase_window_policy_spec.rb6
-rw-r--r--spec/policies/referential_policy_spec.rb8
-rw-r--r--spec/policies/route_policy_spec.rb12
-rw-r--r--spec/policies/routing_constraint_zone_policy_spec.rb10
-rw-r--r--spec/policies/stop_area_policy_spec.rb4
-rw-r--r--spec/policies/time_table_policy_spec.rb10
-rw-r--r--spec/support/pundit/policies.rb5
-rw-r--r--spec/support/pundit/shared_examples.rb51
78 files changed, 593 insertions, 224 deletions
diff --git a/DEVNOTES.md b/DEVNOTES.md
index 2a3915ed2..bcdd37f5e 100644
--- a/DEVNOTES.md
+++ b/DEVNOTES.md
@@ -37,7 +37,7 @@ They are overriden as follows
```ruby
def <destructive>?
- !archived? && organisation_match? && user.has_permission('<resource in plural form>.<action>')
+ !referential_read_only? && organisation_match? && user.has_permission('<resource in plural form>.<action>')
end
```
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index 68d5caf4f..565cccec8 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -48,6 +48,7 @@ class VehicleJourneysController < ChouetteController
@vehicle_journeys = @vehicle_journeys.includes({stop_points: :stop_area})
end
format.html do
+ load_missions
@stop_points_list = []
@stop_points_list = route.stop_points.includes(:stop_area).map do |sp|
{
@@ -175,6 +176,30 @@ class VehicleJourneysController < ChouetteController
end
private
+ def load_missions
+ @all_missions = route.journey_patterns.count > 10 ? [] : route.journey_patterns.map do |item|
+ {
+ id: item.id,
+ "data-item": {
+ id: item.id,
+ name: item.name,
+ published_name: item.published_name,
+ object_id: item.objectid,
+ short_id: item.get_objectid.short_id,
+ stop_area_short_descriptions: item.stop_areas.map do |stop|
+ {
+ stop_area_short_description: {
+ id: stop.id,
+ name: stop.name,
+ object_id: item.objectid
+ }
+ }
+ end
+ }.to_json,
+ text: "<strong>" + item.published_name + " - " + item.get_objectid.short_id + "</strong><br/><small>" + item.registration_number + "</small>"
+ }
+ end
+ end
def vehicle_journey_params
params.require(:vehicle_journey).permit(
{ footnote_ids: [] },
diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb
index df19113db..6600a03f7 100644
--- a/app/helpers/newapplication_helper.rb
+++ b/app/helpers/newapplication_helper.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
module NewapplicationHelper
# Table Builder
@@ -147,7 +148,7 @@ module NewapplicationHelper
content_tag :li, link_to(t("actions.#{action}"), polymorph_url)
end
elsif action == :archive
- unless item.archived?
+ unless item.referential_read_only?
content_tag :li, link_to(t("actions.#{action}"), polymorph_url, method: :put)
end
elsif action == :unarchive
diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js
index 2ae9f5552..8dc542bc8 100644
--- a/app/javascript/journey_patterns/components/JourneyPattern.js
+++ b/app/javascript/journey_patterns/components/JourneyPattern.js
@@ -5,7 +5,6 @@ import actions from '../actions'
export default class JourneyPattern extends Component{
constructor(props){
super(props)
- this.previousCity = undefined
this.previousSpId = undefined
this.updateCosts = this.updateCosts.bind(this)
}
@@ -33,7 +32,7 @@ export default class JourneyPattern extends Component{
}
cityNameChecker(sp, i) {
- return this.props.journeyPatterns.showHeader(sp.object_id + "-" + i)
+ return this.props.journeyPatterns.showHeader((sp.stop_area_object_id || sp.object_id) + "-" + i)
}
spNode(sp, headlined){
@@ -76,7 +75,6 @@ export default class JourneyPattern extends Component{
}
render() {
- this.previousCity = undefined
this.previousSpId = undefined
return (
<div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.object_id ? '' : ' to_record') + (this.props.value.errors ? ' has-error': '') + (this.hasFeature('costs_in_journey_patterns') ? ' with-costs' : '')}>
diff --git a/app/javascript/packs/vehicle_journeys/index.js b/app/javascript/packs/vehicle_journeys/index.js
index 53c5d5417..ab28371fe 100644
--- a/app/javascript/packs/vehicle_journeys/index.js
+++ b/app/javascript/packs/vehicle_journeys/index.js
@@ -70,7 +70,8 @@ var initialState = {
type: '',
modalProps: {},
confirmModal: {}
- }
+ },
+ missions: window.all_missions
}
if (window.jpOrigin){
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js
index 95e56cd76..2675328e3 100644
--- a/app/javascript/vehicle_journeys/actions/index.js
+++ b/app/javascript/vehicle_journeys/actions/index.js
@@ -57,6 +57,7 @@ const actions = {
selectedItem: {
id: selectedJP.id,
objectid: selectedJP.object_id,
+ short_id: selectedJP.short_id,
name: selectedJP.name,
published_name: selectedJP.published_name,
stop_areas: selectedJP.stop_area_short_descriptions,
diff --git a/app/javascript/vehicle_journeys/components/Filters.js b/app/javascript/vehicle_journeys/components/Filters.js
index b6c255c53..2bd912e3e 100644
--- a/app/javascript/vehicle_journeys/components/Filters.js
+++ b/app/javascript/vehicle_journeys/components/Filters.js
@@ -5,7 +5,7 @@ import MissionSelect2 from'./tools/select2s/MissionSelect2'
import VJSelect2 from'./tools/select2s/VJSelect2'
import TimetableSelect2 from'./tools/select2s/TimetableSelect2'
-export default function Filters({filters, pagination, onFilter, onResetFilters, onUpdateStartTimeFilter, onUpdateEndTimeFilter, onToggleWithoutSchedule, onToggleWithoutTimeTable, onSelect2Timetable, onSelect2JourneyPattern, onSelect2VehicleJourney}) {
+export default function Filters({filters, pagination, missions, onFilter, onResetFilters, onUpdateStartTimeFilter, onUpdateEndTimeFilter, onToggleWithoutSchedule, onToggleWithoutTimeTable, onSelect2Timetable, onSelect2JourneyPattern, onSelect2VehicleJourney}) {
return (
<div className='row'>
<div className='col-lg-12'>
@@ -26,6 +26,7 @@ export default function Filters({filters, pagination, onFilter, onResetFilters,
onSelect2JourneyPattern={onSelect2JourneyPattern}
filters={filters}
isFilter={true}
+ values={missions}
/>
</div>
diff --git a/app/javascript/vehicle_journeys/components/tools/CreateModal.js b/app/javascript/vehicle_journeys/components/tools/CreateModal.js
index afc4bc42b..9ab87af3f 100644
--- a/app/javascript/vehicle_journeys/components/tools/CreateModal.js
+++ b/app/javascript/vehicle_journeys/components/tools/CreateModal.js
@@ -11,7 +11,7 @@ export default class CreateModal extends Component {
handleSubmit() {
if (actions.validateFields(...this.refs, $('.vjCreateSelectJP')[0]) && this.props.modal.modalProps.selectedJPModal) {
- this.props.onAddVehicleJourney(this.refs, this.props.modal.modalProps.selectedJPModal, this.props.stopPointsList, this.props.modal.modalProps.selectedCompany)
+ this.props.onAddVehicleJourney(this.refs, this.props.modal.modalProps.selectedJPModal, this.props.stopPointsList, this.props.modal.modalProps.vehicleJourney.company)
this.props.onModalClose()
$('#NewVehicleJourneyModal').modal('hide')
}
@@ -73,6 +73,7 @@ export default class CreateModal extends Component {
<MissionSelect2
selection={this.props.modal.modalProps}
onSelect2JourneyPattern={this.props.onSelect2JourneyPattern}
+ values={this.props.missions}
isFilter={false}
/>
</div>
@@ -155,5 +156,6 @@ CreateModal.propTypes = {
onModalClose: PropTypes.func.isRequired,
onAddVehicleJourney: PropTypes.func.isRequired,
onSelect2JourneyPattern: PropTypes.func.isRequired,
- disabled: PropTypes.bool.isRequired
+ disabled: PropTypes.bool.isRequired,
+ missions: PropTypes.array.isRequired
}
diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
index 36dbb98d5..08d74baba 100644
--- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
@@ -10,14 +10,12 @@ export default class EditVehicleJourney extends Component {
handleSubmit() {
if(actions.validateFields(this.refs) == true) {
- var company;
+ var company = undefined
if(this.props.modal.modalProps.selectedCompany) {
company = this.props.modal.modalProps.selectedCompany
- } else if (typeof this.props.modal.modalProps.vehicleJourney.company === Object) {
+ } else if (typeof this.props.modal.modalProps.vehicleJourney.company === "object") {
company = this.props.modal.modalProps.vehicleJourney.company
- } else {
- company = undefined
- }
+ }
this.props.onEditVehicleJourney(this.refs, company)
this.props.onModalClose()
$('#EditVehicleJourneyModal').modal('hide')
diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
index 2a06df77e..7ab85a1ea 100644
--- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
+++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
@@ -12,50 +12,114 @@ let path = window.location.pathname.split('/', 7).join('/')
export default class BSelect4 extends Component {
constructor(props) {
super(props)
+ this.onSelect = this.onSelect.bind(this)
+ }
+
+ useAjax(){
+ return this.props.values == undefined || this.props.values.length == 0
+ }
+
+ value(){
+ let val = undefined
+ if(this.props.isFilter) {
+ val = this.props.filters.query.journeyPattern
+ }
+ else{
+ if(this.props.selection.selectedJPModal){
+ val = this.props.selection.selectedJPModal
+ }
+ }
+ if(this.useAjax()){
+ val = val.published_name
+ }
+ else{
+ if(val){
+ val = val.id
+ }
+ }
+ return val
+ }
+
+ data(){
+ if(!this.useAjax()){
+ let values = [{}]
+ values.push(...this.props.values)
+ return values
+ }
+ if(this.props.isFilter){
+ return [this.props.filters.query.journeyPattern.published_name]
+ }
+
+ return (this.props.selection.selectedJPModal) ? [this.props.selection.selectedJPModal.published_name] : undefined
+ }
+
+ onSelect(e){
+ if(this.useAjax()){
+ this.props.onSelect2JourneyPattern(e)
+ }
+ else{
+ let data = JSON.parse(e.currentTarget.selectedOptions[0].dataset.item)
+
+ this.props.onSelect2JourneyPattern({params:
+ {
+ data: _.assign({}, e.params.data, data)
+ }
+ })
+ }
+ }
+
+ options(){
+ let options = {
+ theme: 'bootstrap',
+ width: '100%',
+ escapeMarkup: function (markup) { return markup; },
+ templateResult: formatRepo,
+ placeholder: 'Filtrer par code, nom ou OID de mission...',
+ language: require('./fr'),
+ allowClear: false,
+ escapeMarkup: function (markup) { return markup; },
+ }
+ if(this.useAjax()){
+ options = _.assign({}, options, {
+ ajax: {
+ url: origin + path + '/journey_patterns_collection.json',
+ dataType: 'json',
+ delay: '500',
+ data: function(params) {
+ return {
+ q: { published_name_or_objectid_or_registration_number_cont: params.term},
+ };
+ },
+ processResults: function(data, params) {
+ return {
+ results: data.map(
+ item => _.assign(
+ {},
+ item,
+ { text: "<strong>" + item.published_name + " - " + item.short_id + "</strong><br/><small>" + item.registration_number + "</small>" }
+ )
+ )
+ };
+ },
+ cache: true
+ },
+ minimumInputLength: 1
+ })
+ }
+ return options
}
render() {
return (
<Select2
- data={(this.props.isFilter) ? [this.props.filters.query.journeyPattern.published_name] : ((this.props.selection.selectedJPModal) ? [this.props.selection.selectedJPModal.published_name] : undefined)}
- value={(this.props.isFilter) ? this.props.filters.query.journeyPattern.published_name : ((this.props.selection.selectedJPModal) ? this.props.selection.selectedJPModal.published_name : undefined) }
- onSelect={(e) => this.props.onSelect2JourneyPattern(e)}
+ data={this.data()}
+ value={this.value()}
+ onSelect={this.onSelect}
multiple={false}
ref='journey_pattern_id'
className={!this.props.isFilter ? "vjCreateSelectJP" : null}
required={!this.props.isFilter}
- options={{
- allowClear: false,
- theme: 'bootstrap',
- placeholder: 'Filtrer par code, nom ou OID de mission...',
- language: require('./fr'),
- width: '100%',
- ajax: {
- url: origin + path + '/journey_patterns_collection.json',
- dataType: 'json',
- delay: '500',
- data: function(params) {
- return {
- q: { published_name_or_objectid_or_registration_number_cont: params.term},
- };
- },
- processResults: function(data, params) {
- return {
- results: data.map(
- item => _.assign(
- {},
- item,
- { text: "<strong>" + item.published_name + " - " + item.short_id + "</strong><br/><small>" + item.registration_number + "</small>" }
- )
- )
- };
- },
- cache: true
- },
- minimumInputLength: 1,
- escapeMarkup: function (markup) { return markup; },
- templateResult: formatRepo
- }}
+ options={this.options()}
/>
)
}
@@ -63,4 +127,4 @@ export default class BSelect4 extends Component {
const formatRepo = (props) => {
if(props.text) return props.text
-} \ No newline at end of file
+}
diff --git a/app/javascript/vehicle_journeys/containers/Filters.js b/app/javascript/vehicle_journeys/containers/Filters.js
index bec3527f4..a41c599f7 100644
--- a/app/javascript/vehicle_journeys/containers/Filters.js
+++ b/app/javascript/vehicle_journeys/containers/Filters.js
@@ -5,7 +5,8 @@ import Filters from '../components/Filters'
const mapStateToProps = (state) => {
return {
filters: state.filters,
- pagination: state.pagination
+ pagination: state.pagination,
+ missions: state.missions,
}
}
diff --git a/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js b/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
index 5da0bd3e9..0f4a0ea7d 100644
--- a/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
@@ -9,6 +9,7 @@ const mapStateToProps = (state, ownProps) => {
vehicleJourneys: state.vehicleJourneys,
status: state.status,
stopPointsList: state.stopPointsList,
+ missions: state.missions,
}
}
diff --git a/app/javascript/vehicle_journeys/reducers/index.js b/app/javascript/vehicle_journeys/reducers/index.js
index bb24aa185..862c864ae 100644
--- a/app/javascript/vehicle_journeys/reducers/index.js
+++ b/app/javascript/vehicle_journeys/reducers/index.js
@@ -6,6 +6,7 @@ import status from './status'
import filters from './filters'
import editMode from './editMode'
import stopPointsList from './stopPointsList'
+import missions from './missions'
const vehicleJourneysApp = combineReducers({
vehicleJourneys,
@@ -14,7 +15,8 @@ const vehicleJourneysApp = combineReducers({
status,
filters,
editMode,
- stopPointsList
+ stopPointsList,
+ missions
})
export default vehicleJourneysApp
diff --git a/app/javascript/vehicle_journeys/reducers/missions.js b/app/javascript/vehicle_journeys/reducers/missions.js
new file mode 100644
index 000000000..7c1a355c7
--- /dev/null
+++ b/app/javascript/vehicle_journeys/reducers/missions.js
@@ -0,0 +1,6 @@
+export default function missions(state = [], action) {
+ switch (action.type) {
+ default:
+ return state
+ }
+}
diff --git a/app/javascript/vehicle_journeys/reducers/modal.js b/app/javascript/vehicle_journeys/reducers/modal.js
index eae3314e8..c2556303d 100644
--- a/app/javascript/vehicle_journeys/reducers/modal.js
+++ b/app/javascript/vehicle_journeys/reducers/modal.js
@@ -152,7 +152,8 @@ export default function modal(state = {}, action) {
name: window.jpOrigin.name,
published_name: window.jpOrigin.published_name,
objectid: window.jpOrigin.objectid,
- stop_areas: stopAreas
+ stop_areas: stopAreas,
+ missions: state.missions
}
}
return {
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index 34ed51374..a7fd9220c 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -6,7 +6,7 @@ class Calendar < ActiveRecord::Base
include DateSupport
include PeriodSupport
- has_paper_trail
+ has_paper_trail class_name: 'PublicVersion'
belongs_to :organisation
validates_presence_of :name, :short_name, :organisation
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index d4dc82a56..11da77948 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -243,6 +243,14 @@ module Chouette
end
end
+ def custom_fields
+ CustomField.where(resource_type: self.class.name.split("::").last)
+ end
+
+ def custom_field_value key
+ (custom_field_values || {})[key.to_s]
+ end
+
def self.matrix(vehicle_journeys)
Hash[*VehicleJourneyAtStop.where(vehicle_journey_id: vehicle_journeys.pluck(:id)).map do |vjas|
[ "#{vjas.vehicle_journey_id}-#{vjas.stop_point_id}", vjas]
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index 020100f4a..63f380d99 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -1,6 +1,6 @@
class ComplianceCheckSet < ActiveRecord::Base
extend Enumerize
- has_paper_trail
+ has_paper_trail class_name: 'PublicVersion'
belongs_to :referential
belongs_to :compliance_control_set
diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb
index 41076fefc..c0ea692f2 100644
--- a/app/models/compliance_control_set.rb
+++ b/app/models/compliance_control_set.rb
@@ -1,5 +1,5 @@
class ComplianceControlSet < ActiveRecord::Base
- has_paper_trail
+ has_paper_trail class_name: 'PublicVersion'
belongs_to :organisation
has_many :compliance_control_blocks, dependent: :destroy
has_many :compliance_controls, dependent: :destroy
diff --git a/app/models/concerns/objectid_support.rb b/app/models/concerns/objectid_support.rb
index cec36678e..5d1f1a1c2 100644
--- a/app/models/concerns/objectid_support.rb
+++ b/app/models/concerns/objectid_support.rb
@@ -26,5 +26,10 @@ module ObjectidSupport
def objectid_class
get_objectid.try(:class)
end
+
+ def raw_objectid
+ read_attribute(:objectid)
+ end
+
end
end
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
new file mode 100644
index 000000000..e8e76c6b5
--- /dev/null
+++ b/app/models/custom_field.rb
@@ -0,0 +1,7 @@
+class CustomField < ActiveRecord::Base
+
+ extend Enumerize
+ enumerize :field_type, in: %i{list}
+
+ validates :name, uniqueness: {scope: :resource_type}
+end
diff --git a/app/models/merge.rb b/app/models/merge.rb
index 8051eed4d..cef675101 100644
--- a/app/models/merge.rb
+++ b/app/models/merge.rb
@@ -93,10 +93,8 @@ class Merge < ActiveRecord::Base
new.lines.find(line_id).time_tables.find_each do |time_table|
time_table.remove_periods! periods
unless time_table.empty?
- puts "Remove period on #{time_table.inspect}"
time_table.save!
else
- puts "Remove TimeTable #{time_table.inspect}"
time_table.destroy
end
end
@@ -136,9 +134,10 @@ class Merge < ActiveRecord::Base
referential_routes.each do |route|
existing_route = new.routes.find_by line_id: route.line_id, checksum: route.checksum
unless existing_route
+ objectid = Chouette::Route.where(objectid: route.objectid).exists? ? nil : route.objectid
attributes = route.attributes.merge(
id: nil,
- objectid: "merge:route:#{route.checksum}", #FIXME
+ objectid: objectid,
# line_id is the same
# all other primary must be changed
opposite_route_id: nil #FIXME
@@ -149,10 +148,11 @@ class Merge < ActiveRecord::Base
# Stop Points
route_stop_points.each do |stop_point|
+ objectid = Chouette::StopPoint.where(objectid: stop_point.objectid).exists? ? nil : stop_point.objectid
attributes = stop_point.attributes.merge(
id: nil,
route_id: nil,
- objectid: "merge:stop_point:#{route.checksum}-#{stop_point.position}", #FIXME
+ objectid: objectid,
)
new_route.stop_points.build attributes
@@ -170,11 +170,11 @@ class Merge < ActiveRecord::Base
# JourneyPatterns
referential_journey_patterns, referential_journey_patterns_stop_areas_objectids = referential.switch do
- journey_patterns = referential.journey_patterns.includes(:stop_points)
+ journey_patterns = referential.journey_patterns.includes(stop_points: :stop_area)
journey_patterns_stop_areas_objectids = Hash[
journey_patterns.map do |journey_pattern|
- [ journey_pattern.id, journey_pattern.stop_points.map(&:stop_area).map(&:objectid)]
+ [ journey_pattern.id, journey_pattern.stop_points.map(&:stop_area).map(&:raw_objectid)]
end
]
@@ -193,10 +193,10 @@ class Merge < ActiveRecord::Base
existing_journey_pattern = new.journey_patterns.find_by route_id: existing_associated_route.id, checksum: journey_pattern.checksum
unless existing_journey_pattern
+ objectid = Chouette::JourneyPattern.where(objectid: journey_pattern.objectid).exists? ? nil : journey_pattern.objectid
attributes = journey_pattern.attributes.merge(
id: nil,
-
- objectid: "merge:journey_pattern:#{existing_associated_route.checksum}-#{journey_pattern.checksum}", #FIXME
+ objectid: objectid,
# all other primary must be changed
route_id: existing_associated_route.id,
@@ -208,11 +208,15 @@ class Merge < ActiveRecord::Base
stop_areas_objectids = referential_journey_patterns_stop_areas_objectids[journey_pattern.id]
stop_points = existing_associated_route.stop_points.joins(:stop_area).where("stop_areas.objectid": stop_areas_objectids).order(:position)
+ if stop_points.count != stop_areas_objectids.count
+ raise "Can't find StopPoints for #{stop_areas_objectids} : #{stop_points.inspect} #{existing_associated_route.stop_points.inspect}"
+ end
+
attributes.merge!(stop_points: stop_points)
new_journey_pattern = new.journey_patterns.create! attributes
if new_journey_pattern.checksum != journey_pattern.checksum
- raise "Checksum has changed: #{journey_pattern.checksum_source} #{new_journey_pattern.checksum_source}"
+ raise "Checksum has changed for #{journey_pattern.inspect}: #{journey_pattern.checksum_source} #{new_journey_pattern.checksum_source} "
end
end
end
@@ -234,10 +238,10 @@ class Merge < ActiveRecord::Base
existing_vehicle_journey = new.vehicle_journeys.find_by journey_pattern_id: existing_associated_journey_pattern.id, checksum: vehicle_journey.checksum
unless existing_vehicle_journey
+ objectid = Chouette::VehicleJourney.where(objectid: vehicle_journey.objectid).exists? ? nil : vehicle_journey.objectid
attributes = vehicle_journey.attributes.merge(
id: nil,
-
- objectid: "merge:vehicle_journey:#{existing_associated_journey_pattern.checksum}-#{vehicle_journey.checksum}", #FIXME
+ objectid: objectid,
# all other primary must be changed
route_id: existing_associated_journey_pattern.route_id,
@@ -331,10 +335,8 @@ class Merge < ActiveRecord::Base
existing_time_table = line.time_tables.find_by checksum: candidate_time_table.checksum
unless existing_time_table
- # FIXME use real ObjectId
- # Referential id is (temporary) used because the "same" TimeTable can be defined in several merged Referentials
- # and checksum are modified by clean/remove_periods! but this temporary object id is constant
- candidate_time_table.objectid = "merge:time_table:#{line.id}-#{candidate_time_table.checksum}-#{referential.id}:LOC"
+ objectid = Chouette::TimeTable.where(objectid: time_table.objectid).exists? ? nil : time_table.objectid
+ candidate_time_table.objectid = objectid
candidate_time_table.save!
diff --git a/app/models/public_version.rb b/app/models/public_version.rb
new file mode 100644
index 000000000..4dbf6ce27
--- /dev/null
+++ b/app/models/public_version.rb
@@ -0,0 +1,4 @@
+class PublicVersion < PaperTrail::Version
+ # custom behaviour, e.g:
+ self.table_name = :'public.versions'
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 1fd51a779..2b7866d9f 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -252,6 +252,14 @@ class Referential < ActiveRecord::Base
before_destroy :destroy_schema
before_destroy :destroy_jobs
+ def referential_read_only?
+ in_referential_suite? || archived?
+ end
+
+ def in_referential_suite?
+ referential_suite_id.present?
+ end
+
def in_workbench?
workbench_id.present?
end
@@ -315,7 +323,7 @@ class Referential < ActiveRecord::Base
query = "select distinct(public.referential_metadata.referential_id) FROM public.referential_metadata, unnest(line_ids) line, LATERAL unnest(periodes) period
WHERE public.referential_metadata.referential_id
- IN (SELECT public.referentials.id FROM public.referentials WHERE referentials.workbench_id = #{workbench_id} and referentials.archived_at is null #{not_myself})
+ IN (SELECT public.referentials.id FROM public.referentials WHERE referentials.workbench_id = #{workbench_id} and referentials.archived_at is null and referentials.referential_suite_id is null #{not_myself})
AND line in (#{line_ids.join(',')}) and (#{periods_query});"
self.class.connection.select_values(query).map(&:to_i)
@@ -334,9 +342,6 @@ class Referential < ActiveRecord::Base
end
end
- def in_referential_suite?
- referential_suite_id.present?
- end
attr_accessor :inline_clone
def clone_schema
@@ -456,7 +461,7 @@ class Referential < ActiveRecord::Base
# No explicit unlock is needed as it will be released at the end of the
# transaction.
ActiveRecord::Base.connection.execute(
- 'LOCK referentials IN ACCESS EXCLUSIVE MODE'
+ 'LOCK public.referentials IN ACCESS EXCLUSIVE MODE'
)
end
end
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index 3190246ae..f49f4e7cf 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -4,6 +4,7 @@ class Workbench < ActiveRecord::Base
belongs_to :line_referential
belongs_to :stop_area_referential
belongs_to :output, class_name: 'ReferentialSuite'
+ belongs_to :workgroup
has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential
has_many :networks, through: :line_referential
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
new file mode 100644
index 000000000..995917fac
--- /dev/null
+++ b/app/models/workgroup.rb
@@ -0,0 +1,14 @@
+class Workgroup < ActiveRecord::Base
+ belongs_to :line_referential
+ belongs_to :stop_area_referential
+
+ has_many :workbenches
+ has_many :organisations, through: :workbenches
+
+ validates_uniqueness_of :name
+
+ validates_presence_of :line_referential_id
+ validates_presence_of :stop_area_referential_id
+
+ has_many :custom_fields
+end
diff --git a/app/policies/access_link_policy.rb b/app/policies/access_link_policy.rb
index 1f1147f60..f2ea7027f 100644
--- a/app/policies/access_link_policy.rb
+++ b/app/policies/access_link_policy.rb
@@ -6,14 +6,14 @@ class AccessLinkPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('access_links.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('access_links.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('access_links.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_links.destroy')
end
end
diff --git a/app/policies/access_point_policy.rb b/app/policies/access_point_policy.rb
index 41436e77c..4fa887b9e 100644
--- a/app/policies/access_point_policy.rb
+++ b/app/policies/access_point_policy.rb
@@ -6,14 +6,14 @@ class AccessPointPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('access_points.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('access_points.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('access_points.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('access_points.destroy')
end
end
diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb
index dbe4542e7..c44937c9e 100644
--- a/app/policies/application_policy.rb
+++ b/app/policies/application_policy.rb
@@ -81,6 +81,11 @@ class ApplicationPolicy
@is_archived = is_archived
end
+ def referential_read_only?
+ return @is_referential_read_only if instance_variable_defined?(:@is_referential_read_only)
+ @is_referential_read_only = is_referential_read_only
+ end
+
def organisation_match?
user.organisation_id == organisation_id
end
@@ -124,4 +129,13 @@ class ApplicationPolicy
current_referential.try(:archived_at)
end
end
+
+ def is_referential_read_only
+ !!case referential
+ when Referential
+ referential.referential_read_only?
+ else
+ current_referential.try(:referential_read_only?)
+ end
+ end
end
diff --git a/app/policies/connection_link_policy.rb b/app/policies/connection_link_policy.rb
index 240c2a804..9bab5e4db 100644
--- a/app/policies/connection_link_policy.rb
+++ b/app/policies/connection_link_policy.rb
@@ -6,14 +6,14 @@ class ConnectionLinkPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('connection_links.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('connection_links.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('connection_links.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('connection_links.update')
end
end
diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb
index 12bcced17..beb18d151 100644
--- a/app/policies/journey_pattern_policy.rb
+++ b/app/policies/journey_pattern_policy.rb
@@ -7,14 +7,14 @@ class JourneyPatternPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('journey_patterns.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('journey_patterns.update')
end
end
diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb
index e7263cc3b..f7b03b0b5 100644
--- a/app/policies/line_policy.rb
+++ b/app/policies/line_policy.rb
@@ -26,15 +26,15 @@ class LinePolicy < ApplicationPolicy
end
def create_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.create')
end
def edit_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.update')
end
def destroy_footnote?
- !archived? && organisation_match? && user.has_permission?('footnotes.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('footnotes.destroy')
end
def update_footnote? ; edit_footnote? end
diff --git a/app/policies/purchase_window_policy.rb b/app/policies/purchase_window_policy.rb
index 75143a8bd..eb3b04bf7 100644
--- a/app/policies/purchase_window_policy.rb
+++ b/app/policies/purchase_window_policy.rb
@@ -6,15 +6,15 @@ class PurchaseWindowPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.create')
end
def update?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.update')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('purchase_windows.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('purchase_windows.destroy')
end
-end \ No newline at end of file
+end
diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb
index 253917509..af5c14880 100644
--- a/app/policies/referential_policy.rb
+++ b/app/policies/referential_policy.rb
@@ -10,23 +10,23 @@ class ReferentialPolicy < ApplicationPolicy
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('referentials.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('referentials.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('referentials.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('referentials.update')
end
def clone?
- !archived? && create?
+ !referential_read_only? && create?
end
def validate?
- !archived? && create? && organisation_match?
+ !referential_read_only? && create? && organisation_match?
end
def archive?
- record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
+ !referential_read_only? && record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
end
def unarchive?
diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb
index 7e9fe251a..0337a5300 100644
--- a/app/policies/route_policy.rb
+++ b/app/policies/route_policy.rb
@@ -6,15 +6,15 @@ class RoutePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('routes.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('routes.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('routes.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('routes.update')
end
def duplicate?
diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb
index 3cfcf46ff..fd8081bef 100644
--- a/app/policies/routing_constraint_zone_policy.rb
+++ b/app/policies/routing_constraint_zone_policy.rb
@@ -6,14 +6,14 @@ class RoutingConstraintZonePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('routing_constraint_zones.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('routing_constraint_zones.update')
end
end
diff --git a/app/policies/time_table_combination_policy.rb b/app/policies/time_table_combination_policy.rb
index daa6808e4..bba458c18 100644
--- a/app/policies/time_table_combination_policy.rb
+++ b/app/policies/time_table_combination_policy.rb
@@ -7,6 +7,6 @@ class TimeTableCombinationPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('time_tables.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.update')
end
end
diff --git a/app/policies/time_table_policy.rb b/app/policies/time_table_policy.rb
index 92d3aef3e..390c170c7 100644
--- a/app/policies/time_table_policy.rb
+++ b/app/policies/time_table_policy.rb
@@ -7,23 +7,23 @@ class TimeTablePolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('time_tables.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('time_tables.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('time_tables.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('time_tables.update')
end
def actualize?
- !archived? && organisation_match? && edit?
+ !referential_read_only? && organisation_match? && edit?
end
def duplicate?
- !archived? && organisation_match? && create?
+ !referential_read_only? && organisation_match? && create?
end
def month?
diff --git a/app/policies/vehicle_journey_policy.rb b/app/policies/vehicle_journey_policy.rb
index 24040455f..adbc5fd89 100644
--- a/app/policies/vehicle_journey_policy.rb
+++ b/app/policies/vehicle_journey_policy.rb
@@ -6,14 +6,14 @@ class VehicleJourneyPolicy < ApplicationPolicy
end
def create?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.create')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.create')
end
def destroy?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.destroy')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.destroy')
end
def update?
- !archived? && organisation_match? && user.has_permission?('vehicle_journeys.update')
+ !referential_read_only? && organisation_match? && user.has_permission?('vehicle_journeys.update')
end
end
diff --git a/app/views/merges/show.html.slim b/app/views/merges/show.html.slim
index b5d7e9d2d..47e5aa029 100644
--- a/app/views/merges/show.html.slim
+++ b/app/views/merges/show.html.slim
@@ -9,6 +9,6 @@
{ @merge.class.human_attribute_name(:referentials) => @merge.referentials.map(&:name).join(', '),
@merge.class.human_attribute_name(:operator) => @merge.creator,
@merge.class.human_attribute_name(:status) => @merge.status,
- @merge.class.human_attribute_name(:created_at) => l(@merge.created_at),
- @merge.class.human_attribute_name(:started_at) => l(@merge.started_at),
- @merge.class.human_attribute_name(:ended_at) => l(@merge.ended_at) }
+ @merge.class.human_attribute_name(:created_at) => @merge.created_at ? l(@merge.created_at) : '-',
+ @merge.class.human_attribute_name(:started_at) => @merge.started_at ? l(@merge.started_at) : '-',
+ @merge.class.human_attribute_name(:ended_at) => @merge.ended_at ? l(@merge.ended_at) : '-' }
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 96755359c..51041198c 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -1,7 +1,7 @@
- breadcrumb @referential
- page_header_content_for @referential
- content_for :page_header_actions do
- - unless (@referential.archived? || !policy(@referential).edit?)
+ - unless (@referential.referential_read_only? || !policy(@referential).edit?)
= link_to(t('actions.edit'), edit_referential_path(@referential), class: 'btn btn-default')
- content_for :page_header_content do
@@ -22,7 +22,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { t('activerecord.attributes.referential.status') => @referential.archived? ? "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe : "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe,
+ { t('activerecord.attributes.referential.status') => @referential.referential_read_only? ? "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe : "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe,
@referential.human_attribute_name(:validity_period) => (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-'),
@referential.human_attribute_name(:organisation) => @referential.organisation.name,
@referential.human_attribute_name(:published_at) => '-' }
@@ -102,5 +102,5 @@
.modal-footer
button.btn.btn-link type='button' data-dismiss='modal' #{t('cancel')}
- - unless policy(@referential).archived?
+ - unless policy(@referential).referential_read_only?
= f.button :submit, t('actions.clean_up') , class: 'btn btn-primary'
diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim
index ebcac8197..66e90d839 100644
--- a/app/views/vehicle_journeys/index.html.slim
+++ b/app/views/vehicle_journeys/index.html.slim
@@ -26,6 +26,7 @@
| window.line_footnotes = #{raw @footnotes};
| window.perms = #{raw @perms};
| window.features = #{raw @features};
+ | window.all_missions = #{(@all_missions.to_json).html_safe};
| window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe};
= javascript_pack_tag 'vehicle_journeys/index.js'
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index fe0b05330..17ad75051 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -30,7 +30,7 @@
), \
TableBuilderHelper::Column.new( \
key: :status, \
- attribute: Proc.new {|w| w.archived? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>").html_safe} \
+ attribute: Proc.new {|w| w.referential_read_only? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>").html_safe} \
), \
TableBuilderHelper::Column.new( \
key: :organisation, \
diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb
index 8becd23c2..2d06fb88b 100644
--- a/config/initializers/apartment.rb
+++ b/config/initializers/apartment.rb
@@ -39,6 +39,7 @@ Apartment.configure do |config|
'Chouette::Network',
'ReferentialCloning',
'Workbench',
+ 'Workgroup',
'CleanUp',
'CleanUpResult',
'Calendar',
@@ -78,7 +79,8 @@ Apartment.configure do |config|
'ComplianceCheckBlock',
'ComplianceCheckResource',
'ComplianceCheckMessage',
- 'Merge'
+ 'Merge',
+ 'CustomField',
]
# use postgres schemas?
diff --git a/config/initializers/stif.rb b/config/initializers/stif.rb
index 60db50083..a73e4931b 100644
--- a/config/initializers/stif.rb
+++ b/config/initializers/stif.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
Rails.application.config.to_prepare do
Organisation.after_create do |organisation|
line_referential = LineReferential.find_by(name: "CodifLigne")
@@ -6,10 +7,16 @@ Rails.application.config.to_prepare do
line_referential.organisations << organisation
stop_area_referential.organisations << organisation
- organisation.workbenches.find_or_create_by(name: "Gestion de l'offre") do |workbench|
- workbench.line_referential = line_referential
- workbench.stop_area_referential = stop_area_referential
- workbench.objectid_format = Workbench.objectid_format.stif_netex
+ workgroup = Workgroup.find_or_create_by(name: "Gestion de l'offre théorique IDFm") do |w|
+ w.line_referential = line_referential
+ w.stop_area_referential = stop_area_referential
+ end
+
+ workbench = organisation.workbenches.find_or_create_by(name: "Gestion de l'offre") do |w|
+ w.line_referential = line_referential
+ w.stop_area_referential = stop_area_referential
+ w.objectid_format = Workbench.objectid_format.stif_netex
+ w.workgroup = workgroup
Rails.logger.debug "Create Workbench for #{organisation.name}"
end
diff --git a/db/migrate/20180108132310_create_workgroups.rb b/db/migrate/20180108132310_create_workgroups.rb
new file mode 100644
index 000000000..717f05856
--- /dev/null
+++ b/db/migrate/20180108132310_create_workgroups.rb
@@ -0,0 +1,11 @@
+class CreateWorkgroups < ActiveRecord::Migration
+ def change
+ create_table :workgroups do |t|
+ t.string :name
+ t.integer :line_referential_id, limit: 8
+ t.integer :stop_area_referential_id, limit: 8
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20180109133022_add_workgroup_id_to_workbenches.rb b/db/migrate/20180109133022_add_workgroup_id_to_workbenches.rb
new file mode 100644
index 000000000..8736f7fbb
--- /dev/null
+++ b/db/migrate/20180109133022_add_workgroup_id_to_workbenches.rb
@@ -0,0 +1,6 @@
+class AddWorkgroupIdToWorkbenches < ActiveRecord::Migration
+ def change
+ add_column :workbenches, :workgroup_id, :integer, limit: 8
+ add_index :workbenches, :workgroup_id
+ end
+end
diff --git a/db/migrate/20180109144120_create_custom_fields.rb b/db/migrate/20180109144120_create_custom_fields.rb
new file mode 100644
index 000000000..49df645c5
--- /dev/null
+++ b/db/migrate/20180109144120_create_custom_fields.rb
@@ -0,0 +1,14 @@
+class CreateCustomFields < ActiveRecord::Migration
+ def change
+ create_table :custom_fields do |t|
+ t.string :code
+ t.string :resource_type
+ t.string :name
+ t.string :field_type
+ t.json :options
+ t.bigint :workgroup_id
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20180109173815_add_index_resource_type_on_custom_fields.rb b/db/migrate/20180109173815_add_index_resource_type_on_custom_fields.rb
new file mode 100644
index 000000000..326e85806
--- /dev/null
+++ b/db/migrate/20180109173815_add_index_resource_type_on_custom_fields.rb
@@ -0,0 +1,5 @@
+class AddIndexResourceTypeOnCustomFields < ActiveRecord::Migration
+ def change
+ add_index :custom_fields, :resource_type
+ end
+end
diff --git a/db/migrate/20180109180350_add_custom_field_values_to_vehicle_journeys.rb b/db/migrate/20180109180350_add_custom_field_values_to_vehicle_journeys.rb
new file mode 100644
index 000000000..873dc97d4
--- /dev/null
+++ b/db/migrate/20180109180350_add_custom_field_values_to_vehicle_journeys.rb
@@ -0,0 +1,5 @@
+class AddCustomFieldValuesToVehicleJourneys < ActiveRecord::Migration
+ def change
+ add_column :vehicle_journeys, :custom_field_values, :jsonb, default: {}
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index df8243cfd..f55800c8b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180103084612) do
+ActiveRecord::Schema.define(version: 20180109180350) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -281,6 +281,19 @@ ActiveRecord::Schema.define(version: 20180103084612) do
add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree
+ create_table "custom_fields", id: :bigserial, force: :cascade do |t|
+ t.string "code"
+ t.string "resource_type"
+ t.string "name"
+ t.string "field_type"
+ t.json "options"
+ t.integer "workgroup_id", limit: 8
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "custom_fields", ["resource_type"], name: "index_custom_fields_on_resource_type", using: :btree
+
create_table "exports", id: :bigserial, force: :cascade do |t|
t.integer "referential_id", limit: 8
t.string "status"
@@ -942,7 +955,7 @@ ActiveRecord::Schema.define(version: 20180103084612) do
t.integer "route_id", limit: 8
t.integer "journey_pattern_id", limit: 8
t.integer "company_id", limit: 8
- t.string "objectid", null: false
+ t.string "objectid", null: false
t.integer "object_version", limit: 8
t.string "comment"
t.string "status_value"
@@ -954,12 +967,13 @@ ActiveRecord::Schema.define(version: 20180103084612) do
t.integer "number", limit: 8
t.boolean "mobility_restricted_suitability"
t.boolean "flexible_service"
- t.integer "journey_category", default: 0, null: false
+ t.integer "journey_category", default: 0, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "checksum"
t.text "checksum_source"
t.string "data_source_ref"
+ t.jsonb "custom_field_values", default: {}
end
add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree
@@ -985,11 +999,21 @@ ActiveRecord::Schema.define(version: 20180103084612) do
t.integer "stop_area_referential_id", limit: 8
t.integer "output_id", limit: 8
t.string "objectid_format"
+ t.integer "workgroup_id", limit: 8
end
add_index "workbenches", ["line_referential_id"], name: "index_workbenches_on_line_referential_id", using: :btree
add_index "workbenches", ["organisation_id"], name: "index_workbenches_on_organisation_id", using: :btree
add_index "workbenches", ["stop_area_referential_id"], name: "index_workbenches_on_stop_area_referential_id", using: :btree
+ add_index "workbenches", ["workgroup_id"], name: "index_workbenches_on_workgroup_id", using: :btree
+
+ create_table "workgroups", id: :bigserial, force: :cascade do |t|
+ t.string "name"
+ t.integer "line_referential_id", limit: 8
+ t.integer "stop_area_referential_id", limit: 8
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey"
add_foreign_key "api_keys", "organisations"
diff --git a/db/seeds/stif.seeds.rb b/db/seeds/stif.seeds.rb
index 464601557..c87bb7970 100644
--- a/db/seeds/stif.seeds.rb
+++ b/db/seeds/stif.seeds.rb
@@ -5,6 +5,13 @@
stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex", objectid_format: "stif_netex")
line_referential = LineReferential.find_or_create_by!(name: "CodifLigne", objectid_format: "stif_netex")
+workgroup = Workgroup.find_or_create_by!(name: "Gestion de l'offre théorique IDFm") do |w|
+ w.line_referential = line_referential
+ w.stop_area_referential = stop_area_referential
+end
+
+Workbench.update_all workgroup_id: workgroup
+
# Organisations
stif = Organisation.find_or_create_by!(code: "STIF") do |org|
org.name = 'STIF'
diff --git a/spec/factories/custom_fields.rb b/spec/factories/custom_fields.rb
new file mode 100644
index 000000000..2f5fae555
--- /dev/null
+++ b/spec/factories/custom_fields.rb
@@ -0,0 +1,9 @@
+FactoryGirl.define do
+ factory :custom_field do
+ code "code"
+ resource_type "VehicleJourney"
+ sequence(:name){|n| "custom field ##{n}"}
+ field_type "list"
+ options( { "capacity" => "0" } )
+ end
+end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 0f26559d8..98fdd6ad9 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -7,5 +7,6 @@ FactoryGirl.define do
association :line_referential
association :stop_area_referential
association :output, factory: :referential_suite
+ association :workgroup
end
end
diff --git a/spec/factories/workgroups.rb b/spec/factories/workgroups.rb
new file mode 100644
index 000000000..792deddf8
--- /dev/null
+++ b/spec/factories/workgroups.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :workgroup do
+ sequence(:name) { |n| "Workgroup ##{n}" }
+ association :line_referential
+ association :stop_area_referential
+ end
+end
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 83b746d4b..e82697b0a 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'htmlbeautifier'
module TableBuilderHelper
@@ -105,7 +106,7 @@ describe TableBuilderHelper, type: :helper do
TableBuilderHelper::Column.new(
key: :status,
attribute: Proc.new do |w|
- if w.archived?
+ if w.referential_read_only?
("<div class='td-block'><span class='fa fa-archive'></span><span>Conservé</span></div>").html_safe
else
("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").html_safe
diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js
index 2f1daf0da..9515b57f2 100644
--- a/spec/javascript/vehicle_journeys/actions_spec.js
+++ b/spec/javascript/vehicle_journeys/actions_spec.js
@@ -42,6 +42,7 @@ describe('when using select2 to pick a journey pattern', () => {
let selectedJP = {
id: 1,
object_id: 2,
+ short_id: 2,
name: 'test',
published_name: 'test',
stop_area_short_descriptions: ['test']
@@ -51,6 +52,7 @@ describe('when using select2 to pick a journey pattern', () => {
selectedItem:{
id: selectedJP.id,
objectid: selectedJP.object_id,
+ short_id: selectedJP.object_id,
name: selectedJP.name,
published_name: selectedJP.published_name,
stop_areas: selectedJP.stop_area_short_descriptions
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index eb2a31794..3ec2387e5 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -399,8 +399,7 @@ describe Chouette::VehicleJourney, :type => :model do
end
describe ".where_departure_time_between" do
- it "selects vehicle journeys whose departure times are between the
- specified range" do
+ it "selects vehicle journeys whose departure times are between the specified range" do
journey_early = create(
:vehicle_journey,
stop_departure_time: '02:00:00'
@@ -415,7 +414,7 @@ describe Chouette::VehicleJourney, :type => :model do
journey_pattern: journey_pattern,
stop_departure_time: '03:00:00'
)
- journey_late = create(
+ create(
:vehicle_journey,
route: route,
journey_pattern: journey_pattern,
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
new file mode 100644
index 000000000..80873683c
--- /dev/null
+++ b/spec/models/custom_field_spec.rb
@@ -0,0 +1,27 @@
+require 'rails_helper'
+
+RSpec.describe CustomField, type: :model do
+ let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
+
+ context "validates" do
+ it { should validate_uniqueness_of(:name).scoped_to(:resource_type) }
+ end
+
+ context "field access" do
+ let( :custom_field ){ build_stubbed :custom_field }
+
+ it "option's values can be accessed by a key" do
+ expect( custom_field.options['capacity'] ).to eq("0")
+ end
+ end
+
+
+ context "custom fields for a resource" do
+ let!( :fields ){ (1..2).map{ create :custom_field } }
+ it { expect(vj.custom_fields).to eq(fields) }
+ end
+
+ context "custom field_values for a resource" do
+ it { expect(vj.custom_field_value("energy")).to eq(99) }
+ end
+end
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index 45881333f..6d699f759 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -125,19 +125,39 @@ describe Referential, :type => :model do
end
end
- context "used in a ReferentialSuite" do
- before do
- ref.referential_suite_id = 42
+ context "to be referential_read_only or not to be referential_read_only" do
+ let( :referential ){ build_stubbed( :referential ) }
+
+ context "in the beginning" do
+ it{ expect( referential ).not_to be_referential_read_only }
+ end
+
+ context "after archivation" do
+ before{ referential.archived_at = 1.day.ago }
+ it{ expect( referential ).to be_referential_read_only }
end
- it "return true to in_referential_suite?" do
- expect(ref.in_referential_suite?).to be(true)
+ context "used in a ReferentialSuite" do
+ before { referential.referential_suite_id = 42 }
+
+ it{ expect( referential ).to be_referential_read_only }
+
+ it "return true to in_referential_suite?" do
+ expect(referential).to be_in_referential_suite
+ end
+
+ it "don't use detect_overlapped_referentials in validation" do
+ expect(referential).to_not receive(:detect_overlapped_referentials)
+ expect(referential).to be_valid
+ end
end
- it "don't use detect_overlapped_referentials in validation" do
- expect(ref).to_not receive(:detect_overlapped_referentials)
- ref.valid?
+ context "archived and finalised" do
+ before do
+ referential.archived_at = 1.month.ago
+ referential.referential_suite_id = 53
+ end
+ it{ expect( referential ).to be_referential_read_only }
end
end
-
end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index caff00ae4..2f1fe39da 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe Workbench, :type => :model do
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
it { should belong_to(:stop_area_referential) }
+ it { should belong_to(:workgroup) }
it { should belong_to(:output).class_name('ReferentialSuite') }
it { should have_many(:lines).through(:line_referential) }
diff --git a/spec/models/workgroup_spec.rb b/spec/models/workgroup_spec.rb
new file mode 100644
index 000000000..ac8d3fc98
--- /dev/null
+++ b/spec/models/workgroup_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+RSpec.describe Workgroup, type: :model do
+ context "associations" do
+ let( :workgroup ){ build_stubbed :workgroup, line_referential_id: 53, stop_area_referential_id: 42 }
+
+ it{ should have_many(:workbenches) }
+ it{ should validate_uniqueness_of(:name) }
+
+ it 'is not valid without a stop_area_referential' do
+ workgroup.stop_area_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is not valid without a line_referential' do
+ workgroup.line_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is valid with both assoications' do
+ expect( workgroup ).to be_valid
+ end
+ end
+
+ context "find organisations" do
+ let( :workgroup ){ create :workgroup }
+ let!( :workbench1 ){ create :workbench, workgroup: workgroup }
+ let!( :workbench2 ){ create :workbench, workgroup: workgroup }
+
+ it{ expect( Set.new(workgroup.organisations) ).to eq(Set.new([ workbench1.organisation, workbench2.organisation ])) }
+ end
+end
diff --git a/spec/policies/access_link_policy_spec.rb b/spec/policies/access_link_policy_spec.rb
index 6194ae55c..9ba3ffa45 100644
--- a/spec/policies/access_link_policy_spec.rb
+++ b/spec/policies/access_link_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe AccessLinkPolicy, type: :policy do
let( :record ){ build_stubbed :access_link }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "access_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "access_links.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "access_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "access_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "access_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_links.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/access_point_policy_spec.rb b/spec/policies/access_point_policy_spec.rb
index b6bc46eb4..ec7bf1486 100644
--- a/spec/policies/access_point_policy_spec.rb
+++ b/spec/policies/access_point_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe AccessPointPolicy, type: :policy do
let( :record ){ build_stubbed :access_point }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "access_points.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "access_points.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "access_points.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "access_points.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "access_points.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "access_points.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb
index e018902ca..16225c441 100644
--- a/spec/policies/company_policy_spec.rb
+++ b/spec/policies/company_policy_spec.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
RSpec.describe CompanyPolicy, type: :policy do
let( :record ){ build_stubbed :company }
@@ -11,10 +10,10 @@ RSpec.describe CompanyPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
diff --git a/spec/policies/connection_link_policy_spec.rb b/spec/policies/connection_link_policy_spec.rb
index 23e40abe3..6fc9f95df 100644
--- a/spec/policies/connection_link_policy_spec.rb
+++ b/spec/policies/connection_link_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe ConnectionLinkPolicy, type: :policy do
let( :record ){ build_stubbed :connection_link }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "connection_links.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/group_of_line_policy_spec.rb b/spec/policies/group_of_line_policy_spec.rb
index 29fbb1bfb..0aeab97bd 100644
--- a/spec/policies/group_of_line_policy_spec.rb
+++ b/spec/policies/group_of_line_policy_spec.rb
@@ -10,10 +10,10 @@ RSpec.describe GroupOfLinePolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -24,19 +24,19 @@ RSpec.describe GroupOfLinePolicy, type: :policy do
context 'Destructive actions →' do
permissions :create? do
- it_behaves_like 'always forbidden', 'group_of_lines.create', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'always forbidden', 'group_of_lines.destroy', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'always forbidden', 'group_of_lines.update', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'always forbidden', 'group_of_lines.create', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'always forbidden', 'group_of_lines.update', archived: true
+ it_behaves_like 'always forbidden', 'group_of_lines.update', archived_and_finalised: true
end
end
end
diff --git a/spec/policies/journey_pattern_policy_spec.rb b/spec/policies/journey_pattern_policy_spec.rb
index 39f849277..b5e72d813 100644
--- a/spec/policies/journey_pattern_policy_spec.rb
+++ b/spec/policies/journey_pattern_policy_spec.rb
@@ -3,18 +3,18 @@ RSpec.describe JourneyPatternPolicy, type: :policy do
let( :record ){ build_stubbed :journey_pattern }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.destroy", archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.create", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "journey_patterns.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb
index 452606bcf..555008abf 100644
--- a/spec/policies/line_policy_spec.rb
+++ b/spec/policies/line_policy_spec.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
RSpec.describe LinePolicy, type: :policy do
let( :record ){ build_stubbed :line }
@@ -11,10 +10,10 @@ RSpec.describe LinePolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -47,14 +46,14 @@ RSpec.describe LinePolicy, type: :policy do
# ---------------------------
permissions :create_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.create', archived_and_finalised: true
end
permissions :destroy_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.destroy', archived_and_finalised: true
end
permissions :update_footnote? do
- it_behaves_like 'permitted policy and same organisation', 'footnotes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'footnotes.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb
index c09546c22..6dc3f0d46 100644
--- a/spec/policies/network_policy_spec.rb
+++ b/spec/policies/network_policy_spec.rb
@@ -10,10 +10,10 @@ RSpec.describe Chouette::NetworkPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
@@ -24,19 +24,19 @@ RSpec.describe Chouette::NetworkPolicy, type: :policy do
context 'Destructive actions →' do
permissions :create? do
- it_behaves_like 'always forbidden', 'networks.create', archived: true
+ it_behaves_like 'always forbidden', 'networks.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'always forbidden', 'networks.destroy', archived: true
+ it_behaves_like 'always forbidden', 'networks.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'always forbidden', 'networks.update', archived: true
+ it_behaves_like 'always forbidden', 'networks.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'always forbidden', 'networks.create', archived: true
+ it_behaves_like 'always forbidden', 'networks.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'always forbidden', 'networks.update', archived: true
+ it_behaves_like 'always forbidden', 'networks.update', archived_and_finalised: true
end
end
end
diff --git a/spec/policies/purchase_window_policy_spec.rb b/spec/policies/purchase_window_policy_spec.rb
index f078bf288..184152cec 100644
--- a/spec/policies/purchase_window_policy_spec.rb
+++ b/spec/policies/purchase_window_policy_spec.rb
@@ -4,12 +4,12 @@ RSpec.describe PurchaseWindowPolicy, type: :policy do
before { stub_policy_scope(record) }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.create", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.create", archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.destroy", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.destroy", archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', "purchase_windows.update", archived: true
+ it_behaves_like 'permitted policy and same organisation', "purchase_windows.update", archived_and_finalised: true
end
end
diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb
index d00415fc6..8540d3ce9 100644
--- a/spec/policies/referential_policy_spec.rb
+++ b/spec/policies/referential_policy_spec.rb
@@ -32,13 +32,13 @@ RSpec.describe ReferentialPolicy, type: :policy do
# ---------------------------------------
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'referentials.update', archived_and_finalised: true
end
#
@@ -46,7 +46,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
# ------------------
permissions :clone? do
- it_behaves_like 'permitted policy', 'referentials.create', archived: true
+ it_behaves_like 'permitted policy', 'referentials.create', archived_and_finalised: true
end
permissions :archive? do
diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb
index df2e41a89..5dc8be76f 100644
--- a/spec/policies/route_policy_spec.rb
+++ b/spec/policies/route_policy_spec.rb
@@ -3,26 +3,26 @@ RSpec.describe Chouette::RoutePolicy, type: :policy do
let( :record ){ build_stubbed :route }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :duplicate? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'routes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'routes.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'routes.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routes.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/routing_constraint_zone_policy_spec.rb b/spec/policies/routing_constraint_zone_policy_spec.rb
index 2ef15fa95..d619649d3 100644
--- a/spec/policies/routing_constraint_zone_policy_spec.rb
+++ b/spec/policies/routing_constraint_zone_policy_spec.rb
@@ -4,22 +4,22 @@ RSpec.describe RoutingConstraintZonePolicy, type: :policy do
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'routing_constraint_zones.update', archived_and_finalised: true
end
end
diff --git a/spec/policies/stop_area_policy_spec.rb b/spec/policies/stop_area_policy_spec.rb
index 90835d1d8..8144c16e2 100644
--- a/spec/policies/stop_area_policy_spec.rb
+++ b/spec/policies/stop_area_policy_spec.rb
@@ -11,10 +11,10 @@ RSpec.describe StopAreaPolicy, type: :policy do
context 'Non Destructive actions →' do
permissions :index? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
permissions :show? do
- it_behaves_like 'always allowed', 'anything', archived: true
+ it_behaves_like 'always allowed', 'anything', archived_and_finalised: true
end
end
diff --git a/spec/policies/time_table_policy_spec.rb b/spec/policies/time_table_policy_spec.rb
index dad3c13bc..5a2abc61d 100644
--- a/spec/policies/time_table_policy_spec.rb
+++ b/spec/policies/time_table_policy_spec.rb
@@ -3,22 +3,22 @@ RSpec.describe TimeTablePolicy, type: :policy do
let( :record ){ build_stubbed :time_table }
permissions :create? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived_and_finalised: true
end
permissions :destroy? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.destroy', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.destroy', archived_and_finalised: true
end
permissions :edit? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived_and_finalised: true
end
permissions :new? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.create', archived_and_finalised: true
end
permissions :update? do
- it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived: true
+ it_behaves_like 'permitted policy and same organisation', 'time_tables.update', archived_and_finalised: true
end
end
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index a3489d9db..d8d12d735 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -12,11 +12,14 @@ module Support
UserContext.new(user, referential: referential)
end
+ def finalise_referential
+ referential.referential_suite_id = random_int
+ end
+
def remove_permissions(*permissions, from_user:, save: false)
from_user.permissions -= permissions.flatten
from_user.save! if save
end
-
end
module PoliciesMacros
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 49f915626..13f537c6d 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -1,6 +1,6 @@
RSpec.shared_examples 'always allowed' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false |
context 'same organisation →' do
before do
user.organisation_id = referential.organisation_id
@@ -8,11 +8,16 @@ RSpec.shared_examples 'always allowed' do
it "allows a user with the same organisation" do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'does not remove permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.to permit(user_context, record)
end
+
+ it 'does not remove permission for finalised referentials' do
+ finalise_referential
+ expect_it.to permit(user_context, record)
+ end
end
end
@@ -23,27 +28,33 @@ RSpec.shared_examples 'always allowed' do
it "allows a user with a different organisation" do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'does not remove permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.to permit(user_context, record)
end
+ it 'does not remove permission for finalised referentials' do
+ finalise_referential
+ expect_it.to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'always forbidden' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false|
context 'same organisation →' do
before do
user.organisation_id = referential.organisation_id
end
+
it "allows a user with the same organisation" do
expect_it.not_to permit(user_context, record)
end
- if archived
+
+ if archived_and_finalised
it 'still no permission for archived referentials' do
- referential.archived_at = 42.seconds.ago
+ finalise_referential
expect_it.not_to permit(user_context, record)
end
end
@@ -56,17 +67,22 @@ RSpec.shared_examples 'always forbidden' do
it "denies a user with a different organisation" do
expect_it.not_to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'still no permission for archived referentials' do
referential.archived_at = 42.seconds.ago
expect_it.not_to permit(user_context, record)
end
+
+ it 'still no permission for finalised referentials' do
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'permitted policy and same organisation' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false |
context 'permission absent → ' do
it "denies a user with a different organisation" do
@@ -92,18 +108,24 @@ RSpec.shared_examples 'permitted policy and same organisation' do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'removes the permission for archived referentials' do
user.organisation_id = referential.organisation_id
referential.archived_at = 42.seconds.ago
expect_it.not_to permit(user_context, record)
end
+
+ it 'removes the permission for finalised referentials' do
+ user.organisation_id = referential.organisation_id
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
RSpec.shared_examples 'permitted policy' do
- | permission, archived: false|
+ | permission, archived_and_finalised: false|
context 'permission absent → ' do
it "denies user" do
@@ -120,12 +142,17 @@ RSpec.shared_examples 'permitted policy' do
expect_it.to permit(user_context, record)
end
- if archived
+ if archived_and_finalised
it 'removes the permission for archived referentials' do
user.organisation_id = referential.organisation_id
referential.archived_at = 42.seconds.ago
expect_it.not_to permit(user_context, record)
end
+ it 'removes the permission for finalised referentials' do
+ user.organisation_id = referential.organisation_id
+ finalise_referential
+ expect_it.not_to permit(user_context, record)
+ end
end
end
end
@@ -148,4 +175,4 @@ RSpec.shared_examples 'permitted policy outside referential' do
expect_it.to permit(user_context, record)
end
end
-end \ No newline at end of file
+end