account-level user quota defaults, closes #9198
adds (root) account-level setting for (default) user file quotas. defaults to 50 MB. test plan: 1. on a root account, change the default user quota to something other than 50 MB (e.g. 1 MB) 2. as a user in that account: 1. go to /users/self/files/quota . you should see the new quota 2. attempt to upload files. once you have hit/exceeded the quota, you should not be able to upload additional files 3. as a user in multiple (root) accounts: 1. go to /users/self/files/quota . your quota should be the sum of the root account user quotas 2. attempt to upload files. once you have hit/exceeded the quota, you should not be able to upload additional files note that the previous behavior does not change in that one file can exceed your quota. e.g. if your quota is 1 MB, you can upload a 2 MB file. only then will you be prevented from uploading additional files Change-Id: If7f5903fb54eb2b62d80a2b4ee8adfcc48a63683 Reviewed-on: https://gerrit.instructure.com/12005 Reviewed-by: Joe Tanner <joe@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
parent
8931ba5646
commit
d8b52a9605
|
@ -96,6 +96,7 @@ class AccountsController < ApplicationController
|
|||
enable_user_notes = params[:account].delete :enable_user_notes
|
||||
allow_sis_import = params[:account].delete :allow_sis_import
|
||||
global_includes = !!params[:account][:settings].try(:delete, :global_includes)
|
||||
params[:account].delete :default_user_storage_quota_mb unless @account.root_account? && !@account.site_admin?
|
||||
if params[:account][:services]
|
||||
params[:account][:services].slice(*Account.services_exposed_to_ui_hash.keys).each do |key, value|
|
||||
@account.set_service_availability(key, value == '1')
|
||||
|
|
|
@ -21,7 +21,8 @@ class Account < ActiveRecord::Base
|
|||
attr_accessible :name, :turnitin_account_id,
|
||||
:turnitin_shared_secret, :turnitin_comments, :turnitin_pledge,
|
||||
:default_time_zone, :parent_account, :settings, :default_storage_quota,
|
||||
:default_storage_quota_mb, :storage_quota, :ip_filters, :default_locale
|
||||
:default_storage_quota_mb, :storage_quota, :ip_filters, :default_locale,
|
||||
:default_user_storage_quota_mb
|
||||
|
||||
include Workflow
|
||||
belongs_to :parent_account, :class_name => 'Account'
|
||||
|
@ -380,7 +381,26 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
write_attribute(:default_storage_quota, val)
|
||||
end
|
||||
|
||||
def default_user_storage_quota
|
||||
read_attribute(:default_user_storage_quota) ||
|
||||
User.default_storage_quota
|
||||
end
|
||||
|
||||
def default_user_storage_quota=(val)
|
||||
val = val.to_i
|
||||
val = nil if val == User.default_storage_quota || val <= 0
|
||||
write_attribute(:default_user_storage_quota, val)
|
||||
end
|
||||
|
||||
def default_user_storage_quota_mb
|
||||
default_user_storage_quota / 1.megabyte
|
||||
end
|
||||
|
||||
def default_user_storage_quota_mb=(val)
|
||||
self.default_user_storage_quota = val.try(:to_i).try(:megabytes)
|
||||
end
|
||||
|
||||
def has_outcomes?
|
||||
self.learning_outcomes.count > 0
|
||||
end
|
||||
|
|
|
@ -1899,7 +1899,15 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def quota
|
||||
read_attribute(:storage_quota) || Setting.get_cached('user_default_quota', 50.megabytes.to_s).to_i
|
||||
return read_attribute(:storage_quota) if read_attribute(:storage_quota)
|
||||
accounts = associated_root_accounts.reject(&:site_admin?)
|
||||
accounts.empty? ?
|
||||
self.class.default_storage_quota :
|
||||
accounts.sum(&:default_user_storage_quota)
|
||||
end
|
||||
|
||||
def self.default_storage_quota
|
||||
Setting.get_cached('user_default_quota', 50.megabytes.to_s).to_i
|
||||
end
|
||||
|
||||
def update_last_user_note
|
||||
|
|
|
@ -68,10 +68,18 @@
|
|||
<% end %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= f.blabel :default_storage_quota, :en => "Default File Quota" %>
|
||||
<%= f.blabel :default_course_storage_quota, :en => "Default Course File Quota" %>
|
||||
</td>
|
||||
<td><%= t(:megabytes_field, "%{text_field} megabytes", :text_field => f.text_field(:default_storage_quota_mb, :style => "width: 50px;", :title => t(:megabytes_tooltip, "megabytes"))) %></td>
|
||||
<td><%= t(:megabytes_field, "%{text_field} megabytes", :text_field => f.text_field(:default_storage_quota_mb, :id => 'account_default_course_storage_quota', :style => "width: 50px;", :title => t(:megabytes_tooltip, "megabytes"))) %></td>
|
||||
</tr>
|
||||
<% if @account.root_account? && !@account.site_admin? %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= f.blabel :default_user_storage_quota, :en => "Default User File Quota" %>
|
||||
</td>
|
||||
<td><%= t(:megabytes_field, "%{text_field} megabytes", :text_field => f.text_field(:default_user_storage_quota_mb, :id => 'account_default_user_storage_quota', :style => "width: 50px;", :title => t(:megabytes_tooltip, "megabytes"))) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if available_locales.size > 1 %>
|
||||
<tr>
|
||||
<td><%= f.blabel :default_locale, :default_language, :en => "Default Language" %></td>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class AddDefaultUserStorageQuota < ActiveRecord::Migration
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
add_column :accounts, :default_user_storage_quota, :bigint
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :accounts, :default_user_storage_quota
|
||||
end
|
||||
end
|
|
@ -2411,10 +2411,15 @@ define([
|
|||
}
|
||||
fileUpload.updateUploadCount();
|
||||
}, function(data) {
|
||||
$.flashError(
|
||||
data && data.base && data.base.match(/quota/) ?
|
||||
data.base :
|
||||
I18n.t('upload_error', 'There was an error uploading your file')
|
||||
);
|
||||
$("#file_swf").uploadifyCancel(id);
|
||||
$file.find(".cancel_upload_link").hide().end()
|
||||
.find(".status").text("Upload Failed");
|
||||
});
|
||||
}, {skipDefaultError: true});
|
||||
},
|
||||
swfUploadNext: function() {
|
||||
if(fileUpload.swfQueuedAndPendingFiles.length > 0) {
|
||||
|
|
|
@ -1689,4 +1689,17 @@ describe User do
|
|||
User.order_by_sortable_name.all.map(&:sortable_name).should == ["John, John", "Johnson, John"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "quota" do
|
||||
it "should default to User.default_storage_quota" do
|
||||
user().quota.should eql User.default_storage_quota
|
||||
end
|
||||
|
||||
it "should sum up associated root account quotas" do
|
||||
user()
|
||||
@user.associated_root_accounts << Account.create! << (a = Account.create!)
|
||||
a.update_attribute :default_user_storage_quota_mb, a.default_user_storage_quota_mb + 10
|
||||
@user.quota.should eql(2 * User.default_storage_quota + 10.megabytes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,14 +86,22 @@ describe "admin settings tab" do
|
|||
f("#account_name").should have_value "Admin 1"
|
||||
end
|
||||
|
||||
it "should change the default file quota" do
|
||||
mb=300
|
||||
f("#account_default_storage_quota_mb").should have_value "500"
|
||||
replace_content f("#account_default_storage_quota_mb"), mb
|
||||
it "should change the default course file quota" do
|
||||
quota = 300
|
||||
f("#account_default_course_storage_quota").should have_value "500"
|
||||
replace_content f("#account_default_course_storage_quota"), quota
|
||||
click_submit
|
||||
bytes = mb*1048576
|
||||
Account.default.default_storage_quota.should eql bytes
|
||||
f("#account_default_storage_quota_mb").should have_value "300"
|
||||
Account.default.default_storage_quota.should eql quota.megabytes
|
||||
f("#account_default_course_storage_quota").should have_value quota.to_s
|
||||
end
|
||||
|
||||
it "should change the default user file quota" do
|
||||
quota = 100
|
||||
f("#account_default_user_storage_quota").should have_value "50"
|
||||
replace_content f("#account_default_user_storage_quota"), quota
|
||||
click_submit
|
||||
Account.default.default_user_storage_quota.should eql quota.megabytes
|
||||
f("#account_default_user_storage_quota").should have_value quota.to_s
|
||||
end
|
||||
|
||||
it "should change the default language to spanish" do
|
||||
|
|
Loading…
Reference in New Issue