add api endpoint for modified_by in files
fixes CNVS-20737 When working with files, the modified_at attribute is now updated when the modified_by attribute is changed. We are doing this because updated_at doesn't property reflect the file change, just the record change. Test Plan Given you're using something like Postman to test the api When you upload a file via the api Then the 'modified_at' attribute should be set to the time it was modified Given you're using something like Postman to test the api And you have all ready uploaded a file When you update the file content (not just renaming it) Then the 'modified_at' attribute should be set to the time it was modified Given you're using something like Postman to test the api And you have all ready uploaded a file And the file that was uploaded modified_at attribute is null (because the file was uploaded before this change) When you "GET" the file via the api Then the 'modified_at' attribute should be set to the same value as its "updated_at" attribute. Change-Id: I6b1fe761d0a0ed29ce436b178ced7f4c79bb1039 Reviewed-on: https://gerrit.instructure.com/55315 Tested-by: Jenkins Reviewed-by: Clay Diffrient <cdiffrient@instructure.com> Product-Review: Sterling Cobb <sterling@instructure.com> QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
This commit is contained in:
parent
753570d6eb
commit
ea0413808f
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"=>[],
|
||||
|
|
Loading…
Reference in New Issue