diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 0d1c9e6b333..3f463ccb715 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -59,6 +59,10 @@ require 'securerandom' # "unlock_at": { # "type": "datetime" # }, +# "modified_at": { +# "example": "2012-07-06T14:58:50Z", +# "type": "datetime" +# }, # "locked": { # "example": false, # "type": "boolean" @@ -773,6 +777,7 @@ class FilesController < ApplicationController @attachment = @context.attachments.build permission_object ||= @attachment @attachment.user = @current_user + @attachment.modified_at = Time.now.utc if authorized_action(permission_object, @current_user, permission) if @context.respond_to?(:is_a_context?) && @check_quota get_quota @@ -967,7 +972,12 @@ class FilesController < ApplicationController # Need to be careful on this one... we can't let students turn in a # file and then edit it after the fact... params[:attachment].delete(:uploaded_data) if @context.is_a?(User) - @attachment.user = @current_user if params[:attachment][:uploaded_data].present? + + if params[:attachment][:uploaded_data].present? + @attachment.user = @current_user + @attachment.modified_at = Time.now.utc + end + @attachment.attributes = params[:attachment] if just_hide == '1' @attachment.locked = false diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c0be09598b3..18f01095640 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -387,6 +387,7 @@ class Attachment < ActiveRecord::Base end def default_values + self.modified_at = Time.now.utc if self.modified_at.nil? self.display_name = nil if self.display_name && self.display_name.empty? self.display_name ||= unencoded_filename self.file_state ||= "available" diff --git a/lib/api/v1/attachment.rb b/lib/api/v1/attachment.rb index 68f0c0043f2..09f5fa6bd4e 100644 --- a/lib/api/v1/attachment.rb +++ b/lib/api/v1/attachment.rb @@ -85,6 +85,7 @@ module Api::V1::Attachment 'lock_at' => attachment.lock_at, 'hidden_for_user' => hidden_for_user, 'thumbnail_url' => thumbnail_download_url, + 'modified_at' => attachment.modified_at ? attachment.modified_at : attachment.updated_at } locked_json(hash, attachment, user, 'file') @@ -123,6 +124,7 @@ module Api::V1::Attachment @attachment.file_state = 'deleted' @attachment.workflow_state = 'unattached' @attachment.user = @current_user + @attachment.modified_at = Time.now.utc @attachment.content_type = params[:content_type].presence || Attachment.mimetype(@attachment.filename) # Handle deprecated folder path params[:parent_folder_path] ||= params[:folder] diff --git a/spec/apis/file_uploads_spec_helper.rb b/spec/apis/file_uploads_spec_helper.rb index 98af5517da7..c1c7573ce36 100644 --- a/spec/apis/file_uploads_spec_helper.rb +++ b/spec/apis/file_uploads_spec_helper.rb @@ -40,6 +40,7 @@ shared_examples_for "file uploads api" do 'hidden_for_user' => false, 'created_at' => attachment.created_at.as_json, 'updated_at' => attachment.updated_at.as_json, + 'modified_at' => attachment.modified_at.as_json, 'thumbnail_url' => attachment.thumbnail_url } @@ -94,7 +95,8 @@ shared_examples_for "file uploads api" do 'hidden_for_user' => false, 'created_at' => attachment.created_at.as_json, 'updated_at' => attachment.updated_at.as_json, - 'thumbnail_url' => attachment.thumbnail_url + 'thumbnail_url' => attachment.thumbnail_url, + 'modified_at' => attachment.modified_at.as_json } if attachment.context.is_a?(User) || attachment.context.is_a?(Course) diff --git a/spec/apis/v1/conversations_api_spec.rb b/spec/apis/v1/conversations_api_spec.rb index c73f09dcb8b..ec48fc8039f 100644 --- a/spec/apis/v1/conversations_api_spec.rb +++ b/spec/apis/v1/conversations_api_spec.rb @@ -796,7 +796,8 @@ describe ConversationsController, type: :request do 'locked_for_user' => false, 'hidden_for_user' => false, 'created_at' => attachment.created_at.as_json, - 'updated_at' => attachment.updated_at.as_json, + 'updated_at' => attachment.updated_at.as_json, + 'modified_at' => attachment.updated_at.as_json, 'thumbnail_url' => attachment.thumbnail_url }], "participating_user_ids" => [@me.id, @bob.id].sort } ] @@ -978,7 +979,8 @@ describe ConversationsController, type: :request do 'hidden_for_user' => false, 'created_at' => attachment.created_at.as_json, 'updated_at' => attachment.updated_at.as_json, - 'thumbnail_url' => attachment.thumbnail_url + 'thumbnail_url' => attachment.thumbnail_url, + 'modified_at' => attachment.updated_at.as_json } ], "participating_user_ids" => [@me.id, @bob.id].sort diff --git a/spec/apis/v1/discussion_topics_api_spec.rb b/spec/apis/v1/discussion_topics_api_spec.rb index a808d94a904..b485a91518f 100644 --- a/spec/apis/v1/discussion_topics_api_spec.rb +++ b/spec/apis/v1/discussion_topics_api_spec.rb @@ -304,6 +304,7 @@ describe DiscussionTopicsController, type: :request do 'hidden_for_user' => false, 'created_at' => @attachment.created_at.as_json, 'updated_at' => @attachment.updated_at.as_json, + 'modified_at' => @attachment.updated_at.as_json, 'thumbnail_url' => @attachment.thumbnail_url, }], "topic_children"=>[@sub.id], @@ -1131,6 +1132,7 @@ describe DiscussionTopicsController, type: :request do 'created_at' => attachment.created_at.as_json, 'updated_at' => attachment.updated_at.as_json, 'thumbnail_url' => attachment.thumbnail_url, + 'modified_at' => attachment.updated_at.as_json }], "posted_at"=>gtopic.posted_at.as_json, "root_topic_id"=>nil, @@ -2198,6 +2200,7 @@ describe DiscussionTopicsController, type: :request do 'created_at' => @attachment.created_at.as_json, 'updated_at' => @attachment.updated_at.as_json, 'thumbnail_url' => @attachment.thumbnail_url, + 'modified_at' => @attachment.updated_at.as_json } v0 = json['view'][0] diff --git a/spec/apis/v1/files_controller_api_spec.rb b/spec/apis/v1/files_controller_api_spec.rb index 15bdf2f781f..236806ed504 100644 --- a/spec/apis/v1/files_controller_api_spec.rb +++ b/spec/apis/v1/files_controller_api_spec.rb @@ -97,7 +97,8 @@ describe "Files API", type: :request do 'hidden_for_user' => false, 'created_at' => @attachment.created_at.as_json, 'updated_at' => @attachment.updated_at.as_json, - 'thumbnail_url' => nil + 'thumbnail_url' => nil, + 'modified_at' => @attachment.updated_at.as_json }) expect(@attachment.file_state).to eq 'available' end @@ -129,7 +130,8 @@ describe "Files API", type: :request do 'hidden_for_user' => false, 'created_at' => @attachment.created_at.as_json, 'updated_at' => @attachment.updated_at.as_json, - 'thumbnail_url' => nil + 'thumbnail_url' => nil, + 'modified_at' => @attachment.updated_at.as_json }) expect(@attachment.reload.file_state).to eq 'available' end @@ -578,7 +580,8 @@ describe "Files API", type: :request do 'hidden_for_user' => false, 'created_at' => @att.created_at.as_json, 'updated_at' => @att.updated_at.as_json, - 'thumbnail_url' => @att.thumbnail_url + 'thumbnail_url' => @att.thumbnail_url, + 'modified_at' => @att.updated_at.as_json }) end diff --git a/spec/apis/v1/submissions_api_spec.rb b/spec/apis/v1/submissions_api_spec.rb index a823ac17ba8..0f474f17277 100644 --- a/spec/apis/v1/submissions_api_spec.rb +++ b/spec/apis/v1/submissions_api_spec.rb @@ -797,6 +797,7 @@ describe 'Submissions API', type: :request do 'created_at' => sub1.attachments.first.reload.created_at.as_json, 'updated_at' => sub1.attachments.first.updated_at.as_json, 'preview_url' => nil, + 'modified_at' => sub1.attachments.first.modified_at.as_json, 'thumbnail_url' => sub1.attachments.first.thumbnail_url }, ], "submission_history"=> @@ -869,6 +870,7 @@ describe 'Submissions API', type: :request do 'created_at' => sub1.attachments.first.created_at.as_json, 'updated_at' => sub1.attachments.first.updated_at.as_json, 'preview_url' => nil, + 'modified_at' => sub1.attachments.first.modified_at.as_json, 'thumbnail_url' => sub1.attachments.first.thumbnail_url }, ], "body"=>"test!", @@ -957,7 +959,8 @@ describe 'Submissions API', type: :request do 'created_at' => sub2a1.created_at.as_json, 'updated_at' => sub2a1.updated_at.as_json, 'preview_url' => nil, - 'thumbnail_url' => sub2a1.thumbnail_url + 'thumbnail_url' => sub2a1.thumbnail_url, + 'modified_at' => sub2a1.modified_at.as_json }, ], "score"=>9, @@ -985,6 +988,7 @@ describe 'Submissions API', type: :request do 'updated_at' => sub2a1.updated_at.as_json, 'preview_url' => nil, 'thumbnail_url' => sub2a1.thumbnail_url, + 'modified_at' => sub2a1.modified_at.as_json }, ], "submission_comments"=>[],