app/controllers/knitkit/erp_app/desktop/website_controller.rb in knitkit-3.0.0 vs app/controllers/knitkit/erp_app/desktop/website_controller.rb in knitkit-3.2.0
- old
+ new
@@ -6,13 +6,17 @@
before_filter :set_website, :only => [:build_content_tree, :export, :exporttemplate, :website_publications, :set_viewing_version,
:build_host_hash, :activate_publication, :publish, :update, :delete]
def index
- render :json => {:sites => Website.all.collect { |item| item.to_hash(:only => [:id, :name, :title, :subtitle],
- :configuration_id => item.configurations.first.id,
- :url => "http://#{item.config_value('primary_host')}") }}
+ websites = Website.joins(:website_party_roles)
+ .where('website_party_roles.party_id = ?', current_user.party.dba_organization.id)
+ .where('website_party_roles.role_type_id = ?', RoleType.iid('dba_org'))
+
+ render :json => {:sites => websites.all.collect { |item| item.to_hash(:only => [:id, :name, :title, :subtitle],
+ :configuration_id => item.configurations.first.id,
+ :url => "#{request.protocol}#{item.config_value('primary_host')}") }}
end
def build_content_tree
nodes = []
@@ -69,12 +73,12 @@
end
render :inline => "{\"success\":true, \"results\":#{published_websites.count},
\"totalCount\":#{@website.published_websites.count},
\"data\":#{published_websites.to_json(
- :only => [:comment, :id, :version, :created_at, :active],
- :methods => [:viewing, :published_by_username])} }"
+ :only => [:comment, :id, :version, :created_at, :active],
+ :methods => [:viewing, :published_by_username])} }"
end
def activate_publication
begin
current_user.with_capability('activate', 'Website') do
@@ -132,28 +136,38 @@
#set default publication published by user
first_publication = website.published_websites.first
first_publication.published_by = current_user
first_publication.save
+ website_host = WebsiteHost.find_by_host(params[:host])
+ if website_host
+ website_name = website_host.website.name
+ raise "Host #{website_host.host} already used by #{website_name}"
+ end
+
website.hosts << WebsiteHost.create(:host => params[:host])
website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), params[:host])
website.save
website.publish("Publish Default Sections", current_user)
PublishedWebsite.activate(website, 1, current_user)
+ # set the currents users dba_org as the dba_org for this website
+ WebsitePartyRole.create(website: website,
+ party: current_user.party.dba_organization,
+ role_type: RoleType.iid('dba_org'))
+
render :json => {:success => true, :website => website.to_hash(:only => [:id, :name],
:configuration_id => website.configurations.first.id,
:url => "http://#{website.config_value('primary_host')}")}
end
end
rescue => ex
Rails.logger.error("#{ex.message} + #{ex.backtrace.join("\n")}")
render :json => {:success => false, :message => ex.message}
end
-
end
def update
begin
current_user.with_capability('edit', 'Website') do
@@ -180,21 +194,21 @@
def export
zip_path = @website.export
begin
send_file(zip_path.to_s, :stream => false)
- rescue Exception => ex
+ rescue StandardError => ex
raise "Error sending #{zip_path} file"
end
end
def exporttemplate
zip_path = @website.export_template
if zip_path
begin
send_file(zip_path, :stream => false)
- rescue Exception => ex
+ rescue StandardError => ex
raise "Error sending file. Make sure you have a website and an active theme."
end
else
render :inline => {:success => false, :message => 'test'}.to_json
end
@@ -207,28 +221,37 @@
if website
render :inline => {:success => true, :website => website.to_hash(:only => [:id, :name])}.to_json
else
render :inline => {:success => false, :message => message}.to_json
end
+ WebsitePartyRole.create(website: website,
+ party: current_user.party.dba_organization,
+ role_type: RoleType.iid('dba_org'))
ensure
FileUtils.rm_r File.dirname(zip_path) rescue nil
end
- def importtemplate
- website, message = Website.import_template_director(params[:website_data], User.first)
+ def import_template
+ result = Website.import_template(params[:website_data], current_user)
- if website
- render :inline => {:success => true, :website => website.to_hash(:only => [:id, :name])}.to_json
+ if result[:success]
+ render :inline => {:success => true, :website => result[:website].to_hash(:only => [:id, :name])}.to_json
else
- render :inline => {:success => false, :message => message}.to_json
+ render :inline => {:success => false, :message => result[:message]}.to_json
end
end
def has_active_theme
!!Website.find_by_id(params[:website_id]).themes.active.first ? response = 'true' : response = 'false'
render :json => {:success => true, :message => response}
# example found in knitkit module.js
+ end
+
+ def get_current_host
+ current_host = request.host_with_port
+ existing_website_host = WebsiteHost.find_by_host(current_host)
+ render :json => {:success => !existing_website_host.present?, :host => current_host}
end
end # WebsiteController
end # Desktop
end # ErpApp