mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Make s3 region site setting a drop down
This commit is contained in:
parent
ffde23f09f
commit
811a0df68b
8 changed files with 44 additions and 5 deletions
|
@ -83,10 +83,14 @@ Discourse.SiteSetting = Discourse.Model.extend({
|
|||
validValues: function() {
|
||||
var vals;
|
||||
vals = Em.A();
|
||||
this.get("valid_values").each(function(v){
|
||||
vals.addObject({ name: v, value: v });
|
||||
_.each(this.get('valid_values'), function(v) {
|
||||
if(v.length > 0) vals.addObject({ name: v, value: v });
|
||||
});
|
||||
return vals;
|
||||
}.property('valid_values'),
|
||||
|
||||
allowsNone: function() {
|
||||
if ( _.indexOf(this.get('valid_values'), '') >= 0 ) return 'admin.site_settings.none';
|
||||
}.property('valid_values')
|
||||
});
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<h3>{{unbound setting}}</h3>
|
||||
</div>
|
||||
<div class="span11">
|
||||
{{combobox valueAttribute="value" content=validValues value=value}}
|
||||
{{combobox valueAttribute="value" content=validValues value=value none=allowsNone}}
|
||||
<div class='desc'>{{unbound description}}</div>
|
||||
</div>
|
||||
{{#if dirty}}
|
||||
|
|
|
@ -15,7 +15,7 @@ Discourse.ComboboxView = Discourse.View.extend({
|
|||
|
||||
// Add none option if required
|
||||
if (this.get('none')) {
|
||||
buffer.push("<option value=\"\">" + (Ember.String.i18n(this.get('none'))) + "</option>");
|
||||
buffer.push('<option value="">' + (Ember.String.i18n(this.get('none'))) + "</option>");
|
||||
}
|
||||
|
||||
var selected = this.get('value');
|
||||
|
|
9
app/models/s3_region_site_setting.rb
Normal file
9
app/models/s3_region_site_setting.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class S3RegionSiteSetting
|
||||
def self.valid_value?(val)
|
||||
all_values.include? val
|
||||
end
|
||||
|
||||
def self.all_values
|
||||
@all_values ||= ['', 'us-east-1', 'us-west-1', 'us-west-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort
|
||||
end
|
||||
end
|
|
@ -168,7 +168,7 @@ class SiteSetting < ActiveRecord::Base
|
|||
setting(:enable_s3_uploads, false)
|
||||
setting(:s3_access_key_id, '')
|
||||
setting(:s3_secret_access_key, '')
|
||||
setting(:s3_region, '')
|
||||
setting(:s3_region, '', enum: 'S3RegionSiteSetting')
|
||||
setting(:s3_upload_bucket, '')
|
||||
|
||||
setting(:default_trust_level, 0)
|
||||
|
|
|
@ -1183,3 +1183,4 @@ en:
|
|||
show_overriden: 'Only show overridden'
|
||||
title: 'Settings'
|
||||
reset: 'reset to default'
|
||||
none: 'none'
|
||||
|
|
|
@ -34,6 +34,10 @@ describe Admin::SiteSettingsController do
|
|||
xhr :put, :update, id: 'test_setting', value: 'hello'
|
||||
end
|
||||
|
||||
# it 'allows value to be a blank string' do
|
||||
# SiteSetting.expects(:'test_setting=').with('').once
|
||||
# xhr :put, :update, id: 'test_setting', value: ''
|
||||
# end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
21
spec/models/s3_region_site_setting_spec.rb
Normal file
21
spec/models/s3_region_site_setting_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe S3RegionSiteSetting do
|
||||
|
||||
describe 'valid_value?' do
|
||||
it 'returns true for a valid S3 region' do
|
||||
expect(S3RegionSiteSetting.valid_value?('us-west-1')).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false for an invalid S3 region' do
|
||||
expect(S3RegionSiteSetting.valid_value?('the-moon')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'all_values' do
|
||||
it 'returns all the S3 regions and blank' do
|
||||
expect(S3RegionSiteSetting.all_values.sort).to eq(['', 'us-east-1', 'us-west-1', 'us-west-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1'].sort)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue