app/controllers/knitkit/erp_app/desktop/website_controller.rb in knitkit-2.0.10 vs app/controllers/knitkit/erp_app/desktop/website_controller.rb in knitkit-2.0.11
- old
+ new
@@ -40,13 +40,12 @@
:only => [:comment, :id, :version, :created_at, :active],
:methods => [:viewing, :published_by_username])} }"
end
def activate_publication
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'activate', 'Website') do
+ current_user.with_capability('activate', 'Website') do
@website.set_publication_version(params[:version].to_f, current_user)
render :json => {:success => true}
end
rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
@@ -65,38 +64,37 @@
render :json => {:success => true}
end
def publish
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'publish', 'Website') do
+ current_user.with_capability('publish', 'Website') do
@website.publish(params[:comment], current_user)
render :json => {:success => true}
end
rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
render :json => {:success => false, :message => ex.message}
end
end
def new
- model = DesktopApplication.find_by_internal_identifier('knitkit')
- #begin
- #current_user.with_capability(model, 'create', 'Website') do
- result = {}
- website = Website.new
- website.subtitle = params[:subtitle]
- website.title = params[:title]
- website.name = params[:name]
+ begin
+ Website.transaction do
+ current_user.with_capability('create', 'Website') do
+ website = Website.new
+ website.subtitle = params[:subtitle]
+ website.title = params[:title]
+ website.name = params[:name]
- # create homepage
- website_section = WebsiteSection.new
- website_section.title = "Home"
- website_section.in_menu = true
- website.website_sections << website_section
- if website.save
+ # create homepage
+ website_section = WebsiteSection.new
+ website_section.title = "Home"
+ website_section.in_menu = true
+ website.website_sections << website_section
+
+ website.save
website.setup_default_pages
#set default publication published by user
first_publication = website.published_websites.first
first_publication.published_by = current_user
@@ -105,29 +103,26 @@
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)
-
- result[:success] = true
- else
- result[:success] = false
+
+ render :json => {:success => true}
end
- puts website.errors.full_messages
+ end
+ rescue Exception => ex
+ Rails.logger.error("#{ex.message} + #{ex.backtrace.join("\n")}")
+ render :json => {:success => false, :message => ex.message}
+ end
- render :json => result
- #end
- #rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
- #render :json => {:success => false, :message => ex.message}
- #end
end
def update
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'edit', 'Website') do
+ current_user.with_capability('edit', 'Website') do
@website.name = params[:name]
@website.title = params[:title]
@website.subtitle = params[:subtitle]
render :json => @website.save ? {:success => true} : {:success => false}
@@ -137,13 +132,12 @@
end
end
def delete
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'delete', 'Website') do
+ current_user.with_capability('delete', 'Website') do
render :json => @website.destroy ? {:success => true} : {:success => false}
end
rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
render :json => {:success => false, :message => ex.message}
end
@@ -164,13 +158,12 @@
ensure
FileUtils.rm_r File.dirname(zip_path) rescue nil
end
def add_host
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'create', 'Host') do
+ current_user.with_capability('create', 'WebsiteHost') do
website = Website.find(params[:id])
website_host = WebsiteHost.create(:host => params[:host])
website.hosts << website_host
website.save
@@ -185,19 +178,19 @@
:isHost => true,
:leaf => true,
:children => []}
}
end
- rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
+ rescue Exception => ex
+ Rails.logger.error("#{ex.message} + #{ex.backtrace}")
render :json => {:success => false, :message => ex.message}
end
end
def update_host
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'edit', 'Host') do
+ current_user.with_capability('edit', 'WebsiteHost') do
website_host = WebsiteHost.find(params[:id])
website_host.host = params[:host]
website_host.save
render :json => {:success => true}
@@ -206,12 +199,11 @@
render :json => {:success => false, :message => ex.message}
end
end
def delete_host
- model = DesktopApplication.find_by_internal_identifier('knitkit')
begin
- current_user.with_capability(model, 'delete', 'Host') do
+ current_user.with_capability('delete', 'WebsiteHost') do
render :json => WebsiteHost.destroy(params[:id]) ? {:success => true} : {:success => false}
end
rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
render :json => {:success => false, :message => ex.message}
end