Skip to content

Commit

Permalink
Merge commit 'core/quota' into development
Browse files Browse the repository at this point in the history
Conflicts:
	app/workers/member_export_worker.rb
  • Loading branch information
cykod committed Jun 28, 2010
2 parents f72336c + c2826d3 commit f77e459
Show file tree
Hide file tree
Showing 78 changed files with 2,416 additions and 513 deletions.
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Expand Up @@ -174,7 +174,7 @@ def activate_domain(domain=nil)
# Cancel out of domain activations
# if we are testing
if RAILS_ENV == 'test' || RAILS_ENV == 'cucumber' || RAILS_ENV == 'selenium'
DomainModel.activate_domain(Domain.find(CMS_DEFAULTS['testing_domain']).attributes,'production',false)
DomainModel.activate_domain(Domain.find(CMS_DEFAULTS['testing_domain']).get_info,'production',false)
return true
else
domain = request.domain(5)
Expand Down Expand Up @@ -458,7 +458,7 @@ def header_html(html)
# Handles a front-end file upload by turning an uploaded file into a domain file id
def handle_file_upload(parameters,key,options = {})

if !parameters[key].to_s.empty?
if !parameters[key].to_s.empty? && DomainFile.available_file_storage > 0
image_folder = options[:folder] || Configuration.options.default_image_location
file = DomainFile.create(:skip_transform => true,:filename => parameters[key],:parent_id => image_folder,:creator_id => myself.id )
if file.id
Expand All @@ -479,7 +479,7 @@ def handle_image_upload(parameters,key,options = {})

if parameters[key.to_s + "_clear"].to_s == '0'
parameters[key] = nil
elsif !parameters[key].to_s.empty?
elsif !parameters[key].to_s.empty? && DomainFile.available_file_storage > 0
image_folder = options[:folder] || Configuration.options.default_image_location
file = DomainFile.create(:filename => parameters[key],
:parent_id => image_folder,
Expand Down
45 changes: 31 additions & 14 deletions app/controllers/file_controller.rb
Expand Up @@ -174,19 +174,22 @@ def file_manager_update

def upload

dir,file_name = DomainFile.save_uploaded_file(params[:upload_file][:filename])

worker_key = FileWorker.async_do_work(:filename => file_name,
:domain_id => DomainModel.active_domain_id,
:parent_id => params[:upload_file][:parent_id],
:creator_id => myself.id,
:tmp_dir => dir,
:extract_archive => params[:extract_archive],
:replace_same => params[:replace_same]
)
@processing_key = session[:upload_file_worker] = worker_key
respond_to_parent do
render :action => 'upload.rjs'
if DomainFile.available_file_storage > 0
@upload_file = DomainFile.create(:filename => params[:upload_file][:filename], :parent_id => params[:upload_file][:parent_id], :creator_id => myself.id, :skip_transform => true)

worker_key = FileWorker.async_do_work(:domain_file_id => @upload_file.id,
:domain_id => DomainModel.active_domain_id,
:extract_archive => params[:extract_archive],
:replace_same => params[:replace_same]
)
@processing_key = session[:upload_file_worker] = worker_key
respond_to_parent do
render :action => 'upload.rjs'
end
else
respond_to_parent do
render :action => 'upload_failed.rjs'
end
end
end

Expand Down Expand Up @@ -296,7 +299,18 @@ def delete_files
file_id = params[:file_id]

files = DomainFile.find(file_id)
files.each { |fl| fl.destroy }
dirs = []
files.each do |fl|
dirs += fl.storage_directories
end

key = DomainFile::LocalProcessor.set_directories_to_delete dirs
url = "/website/transmit_file/delete/#{DomainModel.active_domain_id}/#{key}"
Server.send_to_all url
DomainFile::LocalProcessor.clear_directories_to_delete key

files.each { |fl| fl.disable_destroy_remote; fl.destroy }

render :nothing => true
end

Expand Down Expand Up @@ -376,4 +390,7 @@ def edit_file
render :partial => 'edit_file'
end
end

def update_storage
end
end
22 changes: 6 additions & 16 deletions app/controllers/manage/clients_controller.rb
Expand Up @@ -2,18 +2,7 @@

class Manage::ClientsController < CmsController # :nodoc: all

# Only system administrators can access this controller
permit 'client_user'

before_filter :validate_admin
def validate_admin
unless myself.client_user.system_admin?
redirect_to :controller => '/manage/system'
return false
end

end

permit 'system_admin'
layout 'manage'

def index
Expand All @@ -28,9 +17,10 @@ def index
include ActiveTable::Controller
active_table :client_table,
Client,
[ ActiveTable::IconHeader.new('', :width=>10),
ActiveTable::StringHeader.new('clients.name',:label => 'Name'),
ActiveTable::StaticHeader.new('Domains/Limit')
[ hdr(:icon, '', :width=>10),
hdr(:static, 'Name'),
hdr(:static, 'Databases/Limit'),
hdr(:number, :max_file_storage, :label => 'Used/Max file storage')
]

def display_client_table(display=true)
Expand Down Expand Up @@ -58,7 +48,7 @@ def new
[ "Clients", url_for(:action => 'index') ],
"New Client"
],"system"
@client = Client.new
@client = Client.new :domain_limit => Client::DEFAULT_DOMAIN_LIMIT, :max_client_users => Client::DEFAULT_MAX_CLIENTS, :max_file_storage => Client::DEFAULT_MAX_FILE_STORAGE
end

def create
Expand Down
138 changes: 58 additions & 80 deletions app/controllers/manage/domains_controller.rb
Expand Up @@ -5,17 +5,10 @@ class Manage::DomainsController < CmsController # :nodoc: all

# All client users can access this controller
# but specific functions are permitted only by the system or client admins
permit 'client_admin'

protected
before_filter :validate_admin
def validate_admin
unless myself.client_user.system_admin?
redirect_to :controller => '/manage/system'
return false
end

end
permit ['system_admin','client_admin']

protected
include Manage::SystemController::Base

before_filter :validate_domain, :except => [ :index, :domains_table, :add ]
def validate_domain
Expand All @@ -32,49 +25,46 @@ def validate_domain

layout "manage"

# need to include
include ActiveTable::Controller
active_table :domains_table,
# need to include
include ActiveTable::Controller
active_table :domains_table,
Domain,
[ ActiveTable::StringHeader.new('domains.name',:label => 'Domain Name'),
ActiveTable::StaticHeader.new('Client'),
ActiveTable::StaticHeader.new('Type'),
ActiveTable::StaticHeader.new('Status'),
ActiveTable::StaticHeader.new('Goto'),
ActiveTable::StaticHeader.new('Delete')

[ hdr(:string, 'domains.name', :label => 'Domain Name'),
hdr(:static, 'Client'),
hdr(:static, 'Type'),
hdr(:static, 'Status'),
hdr(:static, 'Goto'),
hdr(:static, 'Delete')
]

def domains_table(display=true)

if myself.has_role?('system_admin')
if self.system_admin?
@active_table_output = domains_table_generate params, :include => 'client'
else

@active_table_output = domains_table_generate params, :include => 'client', :conditions => [ "client_id = ?", myself.client_user.client_id ]
@active_table_output = domains_table_generate params, :include => 'client', :conditions => [ "client_id = ?", self.client.id ]
end

render :partial => 'domains_table' if display
end

def index
cms_page_info [ ['System',url_for(:controller => '/manage/system')], 'Domains'],'system'

domains_table(false)
render :action => 'list'
end

def edit



cms_page_info [ ['System',url_for(:controller => '/manage/system')], ['Domains',url_for(:controller => '/manage/domains')], ['Edit %s',nil,@domain.name] ],'system'

case @domain.status
when 'initializing':
flash[:notice] = 'Domain is currently initializing and cannot be edited'
redirect_to :action => 'index'
return
when 'working':
flash[:notice] = 'Domain is currently initializing and cannot be edited'
redirect_to :action => 'index'
return
when 'setup':
redirect_to :action => 'setup', :path => @domain.id
return
Expand All @@ -87,23 +77,25 @@ def edit
else
if request.post? && params[:domain][:email_enabled]
@domain.update_attributes(:email_enabled => params[:domain][:email_enabled],
:ssl_enabled => params[:domain][:ssl_enabled])
:ssl_enabled => params[:domain][:ssl_enabled],
:max_file_storage => params[:domain][:max_file_storage])

if @domain.email_enabled
DomainEmail.setup_domain_emails
@domain.execute { DomainEmail.setup_domain_emails }
end
flash.now[:notice] = 'Updated Domain Options'
end
@domain_modules = DomainModule.all_modules(@domain)
@domain_modules = @domain_modules.sort { |a,b| a[:name] <=> b[:name] }

if self.system_admin?
@domain_modules = DomainModule.all_modules(@domain)
@domain_modules = @domain_modules.sort { |a,b| a[:name] <=> b[:name] }
end
end
end

def update_module

if request.post?
if self.system_admin? && request.post? && @domain.status == 'initialized'
mod = params[:mod]

entry = @domain.domain_modules.find_by_name(mod) || @domain.domain_modules.build(:name => mod)
entry.access = params[:access] == 'available' ? 'available' : 'unavailable'
entry.save
Expand All @@ -112,36 +104,15 @@ def update_module
redirect_to :action => 'edit', :path => @domain.id
end

def make_unavailable

mod = params[:mod]

entry = @domain.domain_modules.find_by_name(mod) || @domain.domain_modules.create(:name => mod)
entry.access ='available'
entry.save

redirect_to :action => 'edit', :path => @domain.id
end


def add
cms_page_info [ ['System',url_for(:controller => '/manage/system')], ['Domains',url_for(:controller => '/manage/domains')], 'Add Domain'],'system'

if myself.client_user.system_admin? || myself.client_user.client.domains.count < myself.client_user.client.domain_limit
@domain = Domain.new
else
flash[:notice] = 'Domain Limit Reached'
redirect_to :action => 'index'
return
end

if request.post? && params[:domain]

if params[:commit]
@domain = Domain.new(params[:domain])

# Override the client unless we are a system administrator
@domain.client = myself.client_user.client unless myself.client_user.system_admin?
@domain.client = self.client unless self.system_admin?
@domain.status = 'setup'
if @domain.save
redirect_to :action => 'setup', :path => @domain.id
Expand All @@ -153,45 +124,57 @@ def add
end
end

@clients = Client.find(:all, :order => 'name').collect { |clt| [clt.name,clt.id] } if myself.client_user.system_admin?

@clients = Client.find(:all, :order => 'name').collect { |clt| [clt.name,clt.id] } if self.system_admin?
end

def setup
cms_page_info [ ['System',url_for(:controller => '/manage/system')], ['Domains',url_for(:controller => '/manage/domains')], 'Domain Setup'],'system'

@domain = Domain.find(params[:path][0])


case @domain.status
when 'initializing':
flash[:notice] = 'Domain is currently initializing and cannot be edited'
redirect_to :action => 'index'
return
when 'working':
flash[:notice] = 'Domain is currently initializing and cannot be edited'
redirect_to :action => 'index'
return
when 'initialized':
redirect_to :action => 'edit', :path => @domain.id
return
end

@domain.max_file_storage = DomainDatabase::DEFAULT_MAX_FILE_STORAGE unless @domain.max_file_storage

if request.post? && params[:domain]
if @domain.domain_type == 'domain'
if params[:domain][:database] == 'create'
@domain.attributes = params[:domain].slice(:www_prefix,:active)
@domain.status = 'initializing'
@domain.save
DomainModel.run_worker('Domain',@domain.id,'initialize_database')
flash[:notice] = 'Initializing the %s Domain' / @domain.name
redirect_to :action => 'index'
return
if self.client.can_add_database?
@domain.attributes = params[:domain].slice(:www_prefix,:active)
@domain.max_file_storage = params[:domain][:max_file_storage].blank? ? DomainDatabase::DEFAULT_MAX_FILE_STORAGE : params[:domain][:max_file_storage].to_i

@domain.status = 'initializing'
if @domain.save
DomainModel.run_worker('Domain',@domain.id,'initialize_database')
flash[:notice] = 'Initializing the %s Domain' / @domain.name
redirect_to :action => 'index'
return
end
else
flash[:notice] = 'Database Limit Reached'
end
else
@copy_domain = @domain.client.domains.find_by_id(params[:domain][:database])
if @copy_domain
@domain.database = @copy_domain.database
@domain.file_store = @copy_domain.file_store
@domain.domain_database_id = @copy_domain.domain_database_id
@domain.status = 'initialized'
@domain.save
flash[:notice] = 'Initialized the %s Domain' / @domain.name
redirect_to :action =>'index'
return
if @domain.save
flash[:notice] = 'Initialized the %s Domain' / @domain.name
redirect_to :action =>'index'
return
end
end
end
elsif @domain.domain_type == 'redirect'
Expand All @@ -210,25 +193,20 @@ def setup

def delete
cms_page_info [ ['System',url_for(:controller => '/manage/system')], ['Domains',url_for(:controller => '/manage/domains')], 'Delete Domain'],'system'

end

def destroy

if request.method == :post

if @domain
@domain.destroy

flash[:notice] = "Deleted Domain #{@domain.name}"
redirect_to :action => "index"
return
end

end

flash[:notice] = 'Could not delete domain'
redirect_to :action => "index"

end

end

0 comments on commit f77e459

Please sign in to comment.