Permalink
Browse files

Added S3 as option for attchments

  • Loading branch information...
1 parent dbe1b25 commit 3328b2c3d5b8e367bbbf65b14c1e3f03a87592a0 Qiushi (Billy) He committed with Nov 16, 2009
Showing with 76 additions and 11 deletions.
  1. +2 −1 .gems
  2. +17 −2 app/models/company.rb
  3. +17 −2 app/models/project_file_revision.rb
  4. +18 −3 app/models/user.rb
  5. +20 −2 config/config_schema.yml
  6. +2 −1 config/environment.rb
View
3 .gems
@@ -1,4 +1,5 @@
icalendar --version '>= 1.0.2'
acts_as_ferret --version '>= 0.4.4'
ruby-openid --version '>=2.1.2'
-RedCloth --version '>= 4.0.0'
+RedCloth --version '>= 4.0.0'
+aws-s3
View
@@ -30,8 +30,23 @@ class Company < ActiveRecord::Base
has_many :auto_assign_users, :class_name => 'User', :foreign_key => 'company_id', :conditions => ['auto_assign = ?', true]
has_and_belongs_to_many :projects, :join_table => :project_companies
-
- has_attached_file :logo, :styles => { :thumb => "50x50" }, :default_url => ''
+
+ LOGO_OPTIONS_BASIC = {
+ :styles => { :thumb => "50x50" },
+ :storage => AppConfig.attach_to_s3 ? :s3 : :filesystem,
+ :default_url => ''
+ }
+
+ LOGO_OPTIONS_S3 = {
+ :s3_credentials => {
+ :access_key_id => AppConfig.s3_access_key,
+ :secret_access_key => AppConfig.s3_secret_key
+ },
+ :path => ":attachment/:id/:style.:extension",
+ :bucket => 'htc_company_logo'
+ }
+
+ has_attached_file :logo, LOGO_OPTIONS_BASIC.merge(AppConfig.attach_to_s3 ? LOGO_OPTIONS_S3 : {})
before_create :process_params
before_update :process_update_params
@@ -25,8 +25,23 @@ class ProjectFileRevision < ActiveRecord::Base
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_id'
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_id'
-
- has_attached_file :data, :styles => { :thumb => "50x50" }, :default_url => ''
+
+ DATA_OPTIONS_BASIC = {
+ :styles => { :thumb => "50x50" },
+ :storage => AppConfig.attach_to_s3 ? :s3 : :filesystem,
+ :default_url => ''
+ }
+
+ DATA_OPTIONS_S3 = {
+ :s3_credentials => {
+ :access_key_id => AppConfig.s3_access_key,
+ :secret_access_key => AppConfig.s3_secret_key
+ },
+ :path => ":attachment/:id/:style.:extension",
+ :bucket => 'htc_project_file_revision_data'
+ }
+
+ has_attached_file :data, DATA_OPTIONS_BASIC.merge(AppConfig.attach_to_s3 ? DATA_OPTIONS_S3 : {})
before_create :process_params
before_update :process_update_params
View
@@ -44,9 +44,24 @@ class User < ActiveRecord::Base
has_many :finished_projects, :through => :project_users, :source => :project, :conditions => 'projects.completed_on IS NOT NULL', :order => 'projects.completed_on DESC'
has_and_belongs_to_many :subscriptions, :class_name => 'ProjectMessage', :association_foreign_key => 'message_id', :join_table => :message_subscriptions
-
- has_attached_file :avatar, :styles => { :thumb => "50x50" }, :default_url => ''
-
+
+ AVATAR_OPTIONS_BASIC = {
+ :styles => { :thumb => "50x50" },
+ :storage => AppConfig.attach_to_s3 ? :s3 : :filesystem,
+ :default_url => ''
+ }
+
+ AVATAR_OPTIONS_S3 = {
+ :s3_credentials => {
+ :access_key_id => AppConfig.s3_access_key,
+ :secret_access_key => AppConfig.s3_secret_key
+ },
+ :path => ":attachment/:id/:style.:extension",
+ :bucket => 'htc_user_avatar'
+ }
+
+ has_attached_file :avatar, AVATAR_OPTIONS_BASIC.merge(AppConfig.attach_to_s3 ? AVATAR_OPTIONS_S3 : {})
+
has_many :assigned_times, :class_name => 'ProjectTime', :foreign_key => 'assigned_to_user_id'
def twister_array=(value)
View
@@ -52,12 +52,30 @@ system:
default: 5
comment: ""
order: 9
-
+
+ attach_to_s3:
+ handler: BoolConfigHandler
+ default: false
+ comment: "Enable attachment to Amazon S3"
+ order: 10
+
+ s3_access_key:
+ handler: StringConfigHandler
+ default: ''
+ comment: "Amazon S3 Access Key"
+ order: 11
+
+ s3_secret_key:
+ handler: StringConfigHandler
+ default: ''
+ comment: "Amazon S3 Secret Key"
+ order: 12
+
ferret_index_path:
handler: StringConfigHandler
default: "/tmp/index"
comment: "Relative path to RAILS_ROOT for ferret's index folder."
- order: 10
+ order: 13
general:
site_name:
View
@@ -36,7 +36,8 @@
# optional gems
config.gem 'RedCloth', :version => '>= 4.0.0', :lib => 'redcloth'
-
+ config.gem 'aws-s3', :lib => 'aws/s3'
+
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

0 comments on commit 3328b2c

Please sign in to comment.