Class: Website

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/website.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_host(host) ⇒ Object



101
102
103
104
105
106
107
108
# File 'app/models/website.rb', line 101

def self.find_by_host(host)
  website = nil
  unless host.nil?
    website_host = WebsiteHost.find_by_host(host)
    website = website_host.website unless website_host.nil?
  end
  website
end

.find_site_entry_in_zip(file) ⇒ Object



666
667
668
669
670
671
672
673
# File 'app/models/website.rb', line 666

def find_site_entry_in_zip(file)
  zf = Zip::ZipFile.open(file)
  zf.each_with_index {  |entry, index|
    if entry.name.match(/-template.zip/) && !entry.name.match(/_./)
      return entry
    end
  }
end

.find_theme_entries_in_zip(file) ⇒ Object



675
676
677
678
679
680
681
682
683
684
# File 'app/models/website.rb', line 675

def find_theme_entries_in_zip(file)
  entries = []
  zf = Zip::ZipFile.new(file)
  zf.each_with_index {  |entry, index|
    if entry.name.match(/-theme.zip/) && !entry.name.match(/_./)
      entries << entry
    end
  }
  entries
end

.import(file, current_user) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'app/models/website.rb', line 357

def import(file, current_user)
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
  message = ''
  website = nil

  file = ActionController::UploadedTempfile.new("uploaded-theme").tap do |f|
    f.puts file.read
    f.original_filename = file.original_filename
    f.read # no idea why we need this here, otherwise the zip can't be opened
  end unless file.path

  entries = []
  setup_hash = nil

  tmp_dir = Website.make_tmp_dir
  Zip::ZipFile.open(file.path) do |zip|
    zip.each do |entry|
      f_path = File.join(tmp_dir.to_s, entry.name)
      FileUtils.mkdir_p(File.dirname(f_path))
      zip.extract(entry, f_path) unless File.exist?(f_path)

      next if entry.name =~ /__MACOSX\//
      if entry.name =~ /setup.yml/
        data = ''
        entry.get_input_stream { |io| data = io.read }
        data = StringIO.new(data) if data.present?
        setup_hash = YAML.load(data)
      else
        type = entry.name.split('/')[0]
        name = entry.name.split('/').last
        next if name.nil?

        if File.exist?(f_path) and !File.directory?(f_path)
          entry_hash = {:type => type, :name => name, :path => entry.name}
          entries << entry_hash unless name == 'sections' || name == 'articles' || name == 'excerpts' || name == 'documented contents'
          entry_hash[:data] = File.open(f_path, "rb") { |io| io.read }
        end
      end

    end
  end
  entries.uniq!
  FileUtils.rm_rf(tmp_dir.to_s)

  if Website.find_by_internal_identifier(setup_hash[:internal_identifier]).nil?
    website = Website.new(
        :name => setup_hash[:name],
        :title => setup_hash[:title],
        :subtitle => setup_hash[:subtitle],
        :internal_identifier => setup_hash[:internal_identifier]
    )

    #TODO update to handle configurations

    website.save!

    #set default publication published by user
    first_publication = website.published_websites.first
    first_publication.published_by = current_user
    first_publication.save

    begin
      #handle images
      # entries.each do |entry|
      #   puts "entry type '#{entry[:type]}'"
      #   puts "entry name '#{entry[:name]}'"
      #   puts "entry path '#{entry[:path]}'"
      #   puts "entry data #{!entry[:data].blank?}"
      # end
      # puts "------------------"
      setup_hash[:images].each do |image_asset|
        filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
        #puts "image_asset '#{filename}'"
        content = entries.find { |entry| entry[:type] == 'images' and entry[:path] == filename }
        unless content.nil?
          website.add_file(content[:data], File.join(file_support.root, image_asset[:path], image_asset[:name]))
        end
      end

      #handle files
      setup_hash[:files].each do |file_asset|
        filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
        #puts "file_asset '#{filename}'"
        content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
        unless content.nil?
          file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))

          #handle security
          unless file_asset[:roles].empty?
            capability = file.add_capability(:download)
            file_asset[:roles].each do |role_iid|
              role = SecurityRole.find_by_internal_identifier(role_iid)
              role.add_capability(capability)
            end
          end
        end
      end

      #handle hosts
      setup_hash[:hosts].each do |host|
        website.hosts << WebsiteHost.create(:host => host)
        website.save
      end

      if !setup_hash[:hosts].blank? and !setup_hash[:hosts].empty?
        #set first host as primary host in configuration
        website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), setup_hash[:hosts].first)
        website.save
      end

      #handle sections
      setup_hash[:sections].each do |section_hash|
        build_section(section_hash, entries, website, current_user)
      end
      website.website_sections.update_paths!

      #handle website_navs
      setup_hash[:website_navs].each do |website_nav_hash|
        website_nav = WebsiteNav.new(:name => website_nav_hash[:name])
        website_nav_hash[:items].each do |item|
          website_nav.website_nav_items << build_menu_item(item)
        end
        website.website_navs << website_nav
      end

      website.publish("Website Imported", current_user)

    rescue => ex
      Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
      website.destroy unless website.nil?
      raise ex
    end

    website.save
  else
    message = 'Website already exists with that internal_identifier'
  end

  return website, message
end

.import_template(file, current_user) ⇒ Object



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'app/models/website.rb', line 529

def import_template(file, current_user)
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
  message = ''
  website = nil

  entries = []
  setup_hash = nil

  tmp_dir = Website.make_tmp_dir

  Zip::ZipFile.open(file) do |zip|#passing in a file
    #Zip::ZipFile.open(file.path) do |zip|
    zip.each do |entry|
      f_path = File.join(tmp_dir.to_s, entry.name)
      FileUtils.mkdir_p(File.dirname(f_path))
      zip.extract(entry, f_path) unless File.exist?(f_path)

      next if entry.name =~ /__MACOSX\//
      if entry.name =~ /setup.yml/
        data = ''
        entry.get_input_stream { |io| data = io.read }
        data = StringIO.new(data) if data.present?
        setup_hash = YAML.load(data)
      else
        type = entry.name.split('/')[0]
        name = entry.name.split('/').last
        next if name.nil?

        if File.exist?(f_path) and !File.directory?(f_path)
          entry_hash = {:type => type, :name => name, :path => entry.name}
          entries << entry_hash unless name == 'sections' || name == 'articles' || name == 'excerpts' || name == 'documented contents'
          entry_hash[:data] = File.open(f_path, "rb") { |io| io.read }
        end
      end

    end
  end
  entries.uniq!
  FileUtils.rm_rf(tmp_dir.to_s)

  if Website.find_by_internal_identifier(setup_hash[:internal_identifier]).nil?
    website = Website.new(
        :name => setup_hash[:name],
        :title => setup_hash[:title],
        :subtitle => setup_hash[:subtitle],
        :internal_identifier => setup_hash[:internal_identifier]
    )

    #TODO update to handle configurations

    website.save!

    #set default publication published by user
    first_publication = website.published_websites.first
    first_publication.published_by = current_user
    first_publication.save

    begin
      #handle images
      # entries.each do |entry|
      #   puts "entry type '#{entry[:type]}'"
      #   puts "entry name '#{entry[:name]}'"
      #   puts "entry path '#{entry[:path]}'"
      #   puts "entry data #{!entry[:data].blank?}"
      # end
      # puts "------------------"
      setup_hash[:images].each do |image_asset|
        filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
        #puts "image_asset '#{filename}'"
        content = entries.find { |entry| entry[:type] == 'images' and entry[:path] == filename }
        unless content.nil?
          website.add_file(content[:data], File.join(file_support.root, image_asset[:path], image_asset[:name]))
        end
      end

      #handle files
      setup_hash[:files].each do |file_asset|
        filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
        #puts "file_asset '#{filename}'"
        content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
        unless content.nil?
          file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))

          #handle security
          unless file_asset[:roles].empty?
            capability = file.add_capability(:download)
            file_asset[:roles].each do |role_iid|
              role = SecurityRole.find_by_internal_identifier(role_iid)
              role.add_capability(capability)
            end
          end
        end
      end

      #handle hosts
      if WebsiteHost.last
      setup_hash.merge(:hosts => 'localhost:3000')
      end

      if !setup_hash[:hosts].blank? and !setup_hash[:hosts].empty?
        #set first host as primary host in configuration
        website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), 'localhost:3000')
        website.save
      end

      #handle sections
      setup_hash[:sections].each do |section_hash|
        build_section(section_hash, entries, website, current_user)
      end
      website.website_sections.update_paths!

      #handle website_navs
      setup_hash[:website_navs].each do |website_nav_hash|
        website_nav = WebsiteNav.new(:name => website_nav_hash[:name])
        website_nav_hash[:items].each do |item|
          website_nav.website_nav_items << build_menu_item(item)
        end
        website.website_navs << website_nav
      end

      website.publish("Website Imported", current_user)

    rescue Exception => ex
      Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
      website.destroy unless website.nil?
      raise ex
    end

    website.save
  else
    message = 'Website already exists with that internal_identifier'
  end

  return website, message
end

.import_template_director(file, current_user) ⇒ Object



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'app/models/website.rb', line 498

def import_template_director(file, current_user)
  file_object = file.tempfile
  file_path = file_object.path

  entries = []
  begin
    Zip::ZipFile.open(file_path) { |zip_file|
      zip_file.each { |f|
        f_path=File.join('public/waste', f.name)
        FileUtils.mkdir_p(File.dirname(f_path))
        zip_file.extract(f, f_path) unless File.exist?(f_path)
        entries << f.name
      }
    }

    entries.each do |entry|
      if entry.match(/-template.zip/)
        @website_result = import_template('public/waste/' + entry, current_user)
      end
    end
    entries.each do |entry|
      if entry.match(/-theme.zip/)
        Theme.import_download_item('public/waste/' + entry, @website_result[0])
      end
    end
    return @website_result[0], @website_result[1]
  rescue Exception => e
    return false, "Error"
  end
end

.make_tmp_dirObject



351
352
353
354
355
# File 'app/models/website.rb', line 351

def make_tmp_dir
  Pathname.new(File.join(Rails.root, "/tmp/website_export/tmp_#{Time.now.to_i.to_s}")).tap do |dir|
    FileUtils.mkdir_p(dir) unless dir.exist?
  end
end

Instance Method Details

#active_publicationObject



128
129
130
# File 'app/models/website.rb', line 128

def active_publication
  self.published_websites.where(:active => true).first
end

#add_party_with_role(party, role_type) ⇒ Object



83
84
85
86
# File 'app/models/website.rb', line 83

def add_party_with_role(party, role_type)
  self.website_party_roles << WebsitePartyRole.create(:party => party, :role_type => role_type)
  self.save
end

#all_section_pathsObject



88
89
90
# File 'app/models/website.rb', line 88

def all_section_paths
  WebsiteSection.select(:path).where(:website_id => self.id).collect { |row| row['path'] }
end

#auto_activate_publication?Boolean

Returns:

  • (Boolean)


132
133
134
135
136
137
138
139
# File 'app/models/website.rb', line 132

def auto_activate_publication?
  configuration_item = self.configurations.first.get_item(:auto_active_publications)
  unless configuration_item.nil?
    configuration_item.options.first.value == 'yes'
  else
    false
  end
end

#config_value(config_item_type_iid) ⇒ Object



92
93
94
95
# File 'app/models/website.rb', line 92

def config_value(config_item_type_iid)
  primary_host_config_item_type = ConfigurationItemType.find_by_internal_identifier(config_item_type_iid)
  self.configurations.first.get_configuration_item(primary_host_config_item_type).options.first.value
end

#deactivate_themes!Object



110
111
112
113
114
# File 'app/models/website.rb', line 110

def deactivate_themes!
  themes.each do |theme|
    theme.deactivate!
  end
end

#destroy_sectionsObject

We only want to destroy parent sections as better nested set will destroy children for us



59
60
61
62
63
64
65
66
67
68
# File 'app/models/website.rb', line 59

def destroy_sections
  parents = []
  website_sections.each do |section|
    unless section.child?
      parents << section
    end
  end

  parents.each { |parent| parent.destroy }
end

#email_inquiries?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/models/website.rb', line 97

def email_inquiries?
  config_value('email_inquiries') == 'yes'
end

#exportObject



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'app/models/website.rb', line 241

def export
  tmp_dir = Website.make_tmp_dir
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)

  sections_path = Pathname.new(File.join(tmp_dir, 'sections'))
  FileUtils.mkdir_p(sections_path) unless sections_path.exist?

  articles_path = Pathname.new(File.join(tmp_dir, 'articles'))
  FileUtils.mkdir_p(articles_path) unless articles_path.exist?

  documented_contents_path = Pathname.new(File.join(tmp_dir, 'documented contents'))
  FileUtils.mkdir_p(documented_contents_path) unless documented_contents_path.exist?

  excerpts_path = Pathname.new(File.join(tmp_dir, 'excerpts'))
  FileUtils.mkdir_p(excerpts_path) unless excerpts_path.exist?

  image_assets_path = Pathname.new(File.join(tmp_dir, 'images'))
  FileUtils.mkdir_p(image_assets_path) unless image_assets_path.exist?

  file_assets_path = Pathname.new(File.join(tmp_dir, 'files'))
  FileUtils.mkdir_p(file_assets_path) unless file_assets_path.exist?

  sections.where('parent_id is null').each do |website_section|
    save_section_layout_to_file(sections_path, website_section)
  end

  contents = sections.collect(&:contents).flatten.uniq
  contents.each do |content|
    File.open(File.join(articles_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.body_html) }
    unless content.excerpt_html.blank?
      File.open(File.join(excerpts_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.excerpt_html) }
    end
  end

  online_document_sections.each do |online_documented_section|
    extension = online_documented_section.use_markdown == true ? 'md' : 'html'
    File.open(File.join(documented_contents_path, "#{online_documented_section.internal_identifier}.#{extension}"), 'wb+') { |f| f.puts(online_documented_section.documented_item_published_content_html(active_publication)) }
  end

  self.files.where("directory like '%/sites/#{self.iid}/images%'").all.each do |image_asset|
    contents = file_support.get_contents(File.join(file_support.root, image_asset.directory, image_asset.name))
    FileUtils.mkdir_p(File.join(image_assets_path, image_asset.directory))
    File.open(File.join(image_assets_path, image_asset.directory, image_asset.name), 'wb+') { |f| f.puts(contents) }
  end

  self.files.where("directory like '%/#{Rails.application.config.erp_tech_svcs.file_assets_location}/sites/#{self.iid}%'").all.each do |file_asset|
    contents = file_support.get_contents(File.join(file_support.root, file_asset.directory, file_asset.name))
    FileUtils.mkdir_p(File.join(file_assets_path, file_asset.directory))
    File.open(File.join(file_assets_path, file_asset.directory, file_asset.name), 'wb+') { |f| f.puts(contents) }
  end

  files = []
  Dir.glob("#{tmp_dir.to_s}/**/*").each do |entry|
    next if entry =~ /^\./
    path = entry
    entry = entry.gsub(Regexp.new(tmp_dir.to_s), '')
    entry = entry.gsub(Regexp.new(/^\//), '')
    files << {:path => path, :name => entry}
  end

  File.open(tmp_dir + 'setup.yml', 'wb+') { |f| f.puts(export_setup.to_yaml) }

  (tmp_dir + "#{name}.zip").tap do |file_name|
    file_name.unlink if file_name.exist?
    Zip::ZipFile.open(file_name.to_s, Zip::ZipFile::CREATE) do |zip|
      files.each { |file| zip.add(file[:name], file[:path]) if File.exists?(file[:path]) }
      zip.add('setup.yml', tmp_dir + 'setup.yml')
    end
  end

end

#export_setupObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'app/models/website.rb', line 204

def export_setup
  setup_hash = {
      :name => name,
      :hosts => hosts.collect(&:host),
      :title => title,
      :subtitle => subtitle,
      :internal_identifier => internal_identifier,
      :sections => [],
      :images => [],
      :files => [],
      :website_navs => []
  }

  #TODO update to handle configurations

  setup_hash[:sections] = sections.positioned.collect do |website_section|
    website_section.build_section_hash
  end

  setup_hash[:website_navs] = website_navs.collect do |website_nav|
    {
        :name => website_nav.name,
        :items => website_nav.items.positioned.map { |website_nav_item| website_nav_item.build_menu_item_hash }
    }
  end

  self.files.where("directory like '%/sites/#{self.iid}/images%'").all.each do |image_asset|
    setup_hash[:images] << {:path => image_asset.directory, :name => image_asset.name}
  end

  self.files.where("directory like '%/#{Rails.application.config.erp_tech_svcs.file_assets_location}/sites/#{self.iid}%'").all.each do |file_asset|
    setup_hash[:files] << {:path => file_asset.directory, :name => file_asset.name, :roles => file_asset.roles.uniq.collect { |r| r.internal_identifier }}
  end

  setup_hash
end

#export_templateObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'app/models/website.rb', line 330

def export_template
  tmp_dir = Website.make_tmp_dir
  template_zip_path = export

  if !themes.active.first.is_a?(Theme)
    return false
  end

  theme_zip_path = themes.active.first.export

  zip_file_name = File.join(tmp_dir, self.iid + '-composite.zip')

  Zip::ZipFile.open(zip_file_name, Zip::ZipFile::CREATE) do |zip_file|
    zip_file.add(File.basename(template_zip_path, '.zip') + '-template.zip', template_zip_path)
    zip_file.add(File.basename(theme_zip_path, '.zip') + '-theme.zip', theme_zip_path)
  end

  File.join(tmp_dir, self.iid + '-composite.zip')
end

#iidObject

creating method because we only want a getter, not a setter for iid



79
80
81
# File 'app/models/website.rb', line 79

def iid
  self.internal_identifier
end

#publish(comment, current_user) ⇒ Object



120
121
122
# File 'app/models/website.rb', line 120

def publish(comment, current_user)
  self.published_websites.last.publish(comment, current_user)
end

#publish_element(comment, element, version, current_user) ⇒ Object



116
117
118
# File 'app/models/website.rb', line 116

def publish_element(comment, element, version, current_user)
  self.published_websites.last.publish_element(comment, element, version, current_user)
end

#publish_on_save?Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
# File 'app/models/website.rb', line 141

def publish_on_save?
  configuration_item = self.configurations.first.get_item(:publish_on_save)
  unless configuration_item.nil?
    configuration_item.options.first.value == 'yes'
  else
    false
  end
end

#publishing?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/models/website.rb', line 70

def publishing?
  self.publishing
end

#remove_sites_directoryObject



164
165
166
167
168
169
170
171
# File 'app/models/website.rb', line 164

def remove_sites_directory
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
  begin
    file_support.delete_file(File.join(file_support.root, "sites/#{self.iid}"), :force => true)
  rescue
    #do nothing it may not exist
  end
end

#remove_website_roleObject



173
174
175
# File 'app/models/website.rb', line 173

def remove_website_role
  role.destroy if role
end

#roleObject



150
151
152
# File 'app/models/website.rb', line 150

def role
  SecurityRole.iid(website_role_iid)
end

#save_section_layout_to_file(sections_path, website_section) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'app/models/website.rb', line 313

def save_section_layout_to_file(sections_path, website_section)
  unless website_section.layout.blank?
    File.open(File.join(sections_path, "#{website_section.permalink}.rhtml"), 'wb+') { |f| f.puts(website_section.layout) }
  end

  # we need to handle child sections because internal identifier uniqueness is scoped by parent_id and website_id
  # get all children of this section
  unless website_section.children.empty?
    sections_path = Pathname.new(File.join(sections_path, website_section.permalink))
    FileUtils.mkdir_p(sections_path) unless sections_path.exist?

    website_section.children.each do |website_section_child|
      save_section_layout_to_file(sections_path, website_section_child)
    end
  end
end

#set_publication_version(version, current_user) ⇒ Object



124
125
126
# File 'app/models/website.rb', line 124

def set_publication_version(version, current_user)
  PublishedWebsite.activate(self, version, current_user)
end

#setup_default_pagesObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'app/models/website.rb', line 177

def setup_default_pages
  # create default sections for each widget using widget layout
  widget_classes = [
      ::Widgets::ContactUs::Base,
      ::Widgets::Search::Base,
      ::Widgets::ManageProfile::Base,
      ::Widgets::Login::Base,
      ::Widgets::Signup::Base,
      ::Widgets::ResetPassword::Base
  ]
  profile_page = nil
  widget_classes.each do |widget_class|
    website_section = WebsiteSection.new
    website_section.title = widget_class.title
    website_section.in_menu = true unless ["Login", "Sign Up", "Reset Password"].include?(widget_class.title)
    website_section.layout = widget_class.base_layout
    website_section.save

    profile_page = website_section if widget_class.title == 'Manage Profile'

    self.website_sections << website_section
  end
  self.save
  self.website_sections.update_paths!
  profile_page.secure unless profile_page.nil?
end

#setup_websiteObject



154
155
156
157
158
159
160
161
162
# File 'app/models/website.rb', line 154

def setup_website
  PublishedWebsite.create(:website => self, :version => 0, :active => true, :comment => 'New Site Created')
  SecurityRole.create(:description => "Website #{self.title}", :internal_identifier => website_role_iid) if self.role.nil?
  configuration = ::Configuration.find_template('default_website_configuration').clone(true, "Website #{self.title} Configuration", "Website #{self.title} Configuration".underscore)
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('login_url'), '/login')
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('homepage_url'), '/home')
  self.configurations << configuration
  self.save
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/website.rb', line 14

def should_generate_new_friendly_id?
  new_record? and self.internal_identifier.nil?
end

#to_labelObject



74
75
76
# File 'app/models/website.rb', line 74

def to_label
  self.name
end

#website_role_iidObject



799
800
801
# File 'app/models/website.rb', line 799

def website_role_iid
  "website_#{self.iid}_access"
end