OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
default timestamps for documents
ulferts1bc7c3571dee
diff --git a/frontend/src/app/modules/grids/widgets/documents/documents.component.ts b/frontend/src/app/modules/grids/widgets/documents/documents.component.tsindex 0d6053f6352..a672d184875 100644--- a/frontend/src/app/modules/grids/widgets/documents/documents.component.ts+++ b/frontend/src/app/modules/grids/widgets/documents/documents.component.ts@@ -65,7 +65,7 @@ export class WidgetDocumentsComponent extends AbstractWidgetComponent implements}public get documentsUrl() {- let orders = JSON.stringify([['created_on', 'desc']]);+ let orders = JSON.stringify([['updated_at', 'desc']]);let url = `${this.pathHelper.api.v3.apiV3Base}/documents?sortBy=${orders}&pageSize=10`;diff --git a/modules/dashboards/spec/features/docments_spec.rb b/modules/dashboards/spec/features/docments_spec.rbindex 8b2354581bb..cf5c5fed6cc 100644--- a/modules/dashboards/spec/features/docments_spec.rb+++ b/modules/dashboards/spec/features/docments_spec.rb@@ -76,7 +76,7 @@ describe 'Documents widget on dashboard', type: :feature, js: true doexpect(page).to have_content visible_document.descriptionexpect(page)- .to have_content visible_document.created_on.strftime('%m/%d/%Y')+ .to have_content visible_document.created_at.strftime('%m/%d/%Y')expect(page).to have_no_content invisible_document.titlediff --git a/modules/documents/app/models/document.rb b/modules/documents/app/models/document.rbindex f5ade2cdf03..9d018697c72 100644--- a/modules/documents/app/models/document.rb+++ b/modules/documents/app/models/document.rb@@ -36,14 +36,15 @@ class Document < ActiveRecord::Baseacts_as_journalizedacts_as_event title: Proc.new { |o| "#{Document.model_name.human}: #{o.title}" },url: Proc.new { |o| { controller: '/documents', action: 'show', id: o.id } },- datetime: :created_on,+ datetime: :created_at,author: ( Proc.new do |o|o.attachments.find(:first, order: "#{Attachment.table_name}.created_at ASC").try(:author)end)acts_as_searchable columns: ['title', "#{table_name}.description"],include: :project,- references: :projects+ references: :projects,+ date_column: "#{table_name}.created_at"validates_presence_of :project, :title, :categoryvalidates_length_of :title, maximum: 60@@ -73,11 +74,11 @@ class Document < ActiveRecord::Basedef updated_onunless @updated_on- # attachments has a default order that conflicts with `created_on DESC`+ # attachments has a default order that conflicts with `created_at DESC`# #reorder removes that default order but rather than #unscoped keeps the# scoping by this documenta = attachments.reorder(Arel.sql('created_at DESC')).first- @updated_on = (a && a.created_at) || created_on+ @updated_on = (a && a.created_at) || created_atend@updated_onenddiff --git a/modules/documents/app/models/queries/documents/orders/default_order.rb b/modules/documents/app/models/queries/documents/orders/default_order.rbindex 5f8b5aceeb6..3829f1a23ec 100644--- a/modules/documents/app/models/queries/documents/orders/default_order.rb+++ b/modules/documents/app/models/queries/documents/orders/default_order.rb@@ -32,6 +32,6 @@ class Queries::Documents::Orders::DefaultOrder < Queries::BaseOrderself.model = Documentdef self.key- /\A(id|created_on)\z/+ /\A(id|created_at|updated_at)\z/endenddiff --git a/modules/documents/app/views/documents/show.html.erb b/modules/documents/app/views/documents/show.html.erbindex 10a09156b72..d1e15e57c8a 100644--- a/modules/documents/app/views/documents/show.html.erb+++ b/modules/documents/app/views/documents/show.html.erb@@ -29,7 +29,7 @@ See docs/COPYRIGHT.rdoc for more details.<% html_title h(@document.title) -%><%= toolbar title: @document.title,- subtitle: "#{@document.category.name} - #{format_date @document.created_on}" do %>+ subtitle: "#{@document.category.name} - #{format_date @document.created_at}" do %><% if authorize_for(:documents, :edit) %><li class="toolbar-item"><%= link_to({controller: '/documents', action: 'edit', id: @document}, class: 'button', accesskey: accesskey(:edit)) do %>diff --git a/modules/documents/app/views/my/blocks/_documents.html.erb b/modules/documents/app/views/my/blocks/_documents.html.erbindex 0e6bd823313..9ee63e91564 100644--- a/modules/documents/app/views/my/blocks/_documents.html.erb+++ b/modules/documents/app/views/my/blocks/_documents.html.erb@@ -40,6 +40,6 @@ See docs/COPYRIGHT.rdoc for more details.<%= render(partial: 'documents/document',collection: Document.limit(10)- .order("#{Document.table_name}.created_on DESC")+ .order("#{Document.table_name}.created_at DESC").where("#{Document.table_name}.project_id in (#{project_ids.join(',')})").includes(:project)) unless project_ids.empty? %>diff --git a/modules/documents/app/views/my_projects_overviews/blocks/_documents.html.erb b/modules/documents/app/views/my_projects_overviews/blocks/_documents.html.erbindex ca2a6bc5978..833bde7b950 100644--- a/modules/documents/app/views/my_projects_overviews/blocks/_documents.html.erb+++ b/modules/documents/app/views/my_projects_overviews/blocks/_documents.html.erb@@ -39,5 +39,5 @@ See docs/COPYRIGHT.rdoc for more details.<% if current_user.allowed_to?(:view_documents, @project)%><%= render(:partial => 'documents/document',- :collection => Document.where(project_id: @project.id).limit(10).order("created_on DESC")) %>+ :collection => Document.where(project_id: @project.id).limit(10).order("created_at DESC")) %><% end %>diff --git a/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb b/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rbindex 0052ba0c4ff..08629f994b9 100644--- a/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb+++ b/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb@@ -26,10 +26,9 @@# See docs/COPYRIGHT.rdoc for more details.#++-require Rails.root.join("db","migrate","migration_utils","migration_squasher").to_s+require Rails.root.join("db", "migrate", "migration_utils", "migration_squasher").to_s# This migration aggregates the migrations detailed in MIGRATION_FILESclass ToV710AggregatedDocumentsMigrations < ActiveRecord::Migration[5.1]-MIGRATION_FILES = <<-MIGRATIONS20130807085604_create_document_journals.rb20130814131242_create_documents_tables.rb@@ -39,21 +38,21 @@ class ToV710AggregatedDocumentsMigrations < ActiveRecord::Migration[5.1]def upMigration::MigrationSquasher.squash(migrations) docreate_table "documents", id: :integer do |t|- t.integer "project_id", :default => 0, :null => false- t.integer "category_id", :default => 0, :null => false- t.string "title", :limit => 60, :default => "", :null => false+ t.integer "project_id", default: 0, null: false+ t.integer "category_id", default: 0, null: false+ t.string "title", limit: 60, default: "", null: falset.text "description"t.datetime "created_on"end- add_index "documents", ["category_id"], :name => "index_documents_on_category_id"- add_index "documents", ["created_on"], :name => "index_documents_on_created_on"- add_index "documents", ["project_id"], :name => "documents_project_id"+ add_index "documents", ["category_id"], name: "index_documents_on_category_id"+ add_index "documents", ["created_on"], name: "index_documents_on_created_on"+ add_index "documents", ["project_id"], name: "documents_project_id"create_table :document_journals, id: :integer do |t|- t.integer :journal_id, :null => false- t.integer :project_id, :default => 0, :null => false- t.integer :category_id, :default => 0, :null => false- t.string :title, :limit => 60, :default => "", :null => false+ t.integer :journal_id, null: false+ t.integer :project_id, default: 0, null: false+ t.integer :category_id, default: 0, null: false+ t.string :title, limit: 60, default: "", null: falset.text :descriptiont.datetime :created_onenddiff --git a/modules/documents/db/migrate/20200217090016_document_timestamps.rb b/modules/documents/db/migrate/20200217090016_document_timestamps.rbnew file mode 100644index 00000000000..0ae175fafa1--- /dev/null+++ b/modules/documents/db/migrate/20200217090016_document_timestamps.rb@@ -0,0 +1,12 @@+class DocumentTimestamps < ActiveRecord::Migration[6.0]+ def change+ add_column :documents, :updated_at, :datetime+ rename_column :documents, :created_on, :created_at+ # We do not need the timestamp on the data table, as we already have it on the journals table.+ remove_column :document_journals, :created_on, :datetime++ reversible do |change|+ change.up { Document.update_all("updated_at = created_at") }+ end+ end+enddiff --git a/modules/documents/lib/api/v3/documents/document_representer.rb b/modules/documents/lib/api/v3/documents/document_representer.rbindex 6c80312ee0b..a67c10b67c2 100644--- a/modules/documents/lib/api/v3/documents/document_representer.rb+++ b/modules/documents/lib/api/v3/documents/document_representer.rb@@ -47,8 +47,8 @@ module APIformattable_property :description- date_time_property :created_on,- as: 'createdAt'+ date_time_property :created_at+ date_time_property :updated_atassociated_resource :project,link: ->(*) dodiff --git a/modules/documents/spec/api/v3/documents/document_representer_rendering_spec.rb b/modules/documents/spec/api/v3/documents/document_representer_rendering_spec.rbindex 2d509c31779..c35cbe58f09 100644--- a/modules/documents/spec/api/v3/documents/document_representer_rendering_spec.rb+++ b/modules/documents/spec/api/v3/documents/document_representer_rendering_spec.rb@@ -33,7 +33,6 @@ describe ::API::V3::Documents::DocumentRepresenter, 'rendering' dolet(:document) doFactoryBot.build_stubbed(:document,- created_on: Time.now,description: 'Some description') do |document|allow(document).to receive(:project)@@ -97,10 +96,15 @@ describe ::API::V3::Documents::DocumentRepresenter, 'rendering' doendit_behaves_like 'has UTC ISO 8601 date and time' do- let(:date) { document.created_on }+ let(:date) { document.created_at }let(:json_path) { 'createdAt' }end+ it_behaves_like 'has UTC ISO 8601 date and time' do+ let(:date) { document.updated_at }+ let(:json_path) { 'updatedAt' }+ end+it_behaves_like 'API V3 formattable', 'description' dolet(:format) { 'markdown' }let(:raw) { document.description }@@ -112,7 +116,7 @@ describe ::API::V3::Documents::DocumentRepresenter, 'rendering' doit 'has project embedded' doexpect(subject).to be_json_eql(project.name.to_json)- .at_path('_embedded/project/name')+ .at_path('_embedded/project/name')endendenddiff --git a/modules/documents/spec/models/document_spec.rb b/modules/documents/spec/models/document_spec.rbindex 5089bb49e80..8176cbec9c2 100644--- a/modules/documents/spec/models/document_spec.rb+++ b/modules/documents/spec/models/document_spec.rb@@ -98,16 +98,16 @@ describe Document doit "without attachments, the updated-on-date is taken from the document's date" dodocument = FactoryBot.create(:document, project: project)expect(document.attachments).to be_empty- expect(document.created_on).to eql document.updated_on+ expect(document.created_at).to eql document.updated_atendenddescribe "acts as event" dolet(:now) { Time.zone.now }- let(:document) {+ let(:document) doFactoryBot.build(:document,- created_on: now)- }+ created_at: now)+ endit { expect(document.event_datetime.to_i).to eq(now.to_i) }enddiff --git a/modules/my_page/spec/features/my/documents_spec.rb b/modules/my_page/spec/features/my/documents_spec.rbindex 7f552e47614..740c5b632cb 100644--- a/modules/my_page/spec/features/my/documents_spec.rb+++ b/modules/my_page/spec/features/my/documents_spec.rb@@ -72,7 +72,7 @@ describe 'My page documents widget', type: :feature, js: true doexpect(page).to have_content visible_document.descriptionexpect(page)- .to have_content visible_document.created_on.strftime('%m/%d/%Y')+ .to have_content visible_document.created_at.strftime('%m/%d/%Y')expect(page).to have_no_content invisible_document.title