cas-cms 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/assets/javascripts/cas/application.js +5 -0
  4. data/app/assets/stylesheets/cas/form.sass +8 -3
  5. data/app/assets/stylesheets/cas/layout.sass +6 -2
  6. data/app/assets/stylesheets/cas/typography.sass +1 -1
  7. data/app/controllers/cas/application_controller.rb +10 -0
  8. data/app/controllers/cas/devise/sessions_controller.rb +2 -0
  9. data/app/controllers/cas/sites/application_controller.rb +15 -0
  10. data/app/controllers/cas/{sections → sites/sections}/application_controller.rb +2 -2
  11. data/app/controllers/cas/{sections → sites/sections}/categories_controller.rb +3 -3
  12. data/app/controllers/cas/{sections → sites/sections}/contents_controller.rb +4 -4
  13. data/app/controllers/cas/sites/sections_controller.rb +7 -0
  14. data/app/controllers/cas/{users_controller.rb → sites/users_controller.rb} +20 -6
  15. data/app/models/cas/site.rb +5 -0
  16. data/app/models/cas/sites_user.rb +7 -0
  17. data/app/models/cas/user.rb +14 -6
  18. data/app/views/cas/{sections → sites/sections}/categories/_form.html.erb +3 -3
  19. data/app/views/cas/{sections → sites/sections}/categories/edit.html.erb +1 -1
  20. data/app/views/cas/{sections → sites/sections}/categories/index.html.erb +2 -2
  21. data/app/views/cas/sites/sections/categories/new.html.erb +5 -0
  22. data/app/views/cas/{sections → sites/sections}/contents/_form_attachments.html.erb +0 -0
  23. data/app/views/cas/{sections → sites/sections}/contents/_form_attachments_template.html.erb +0 -0
  24. data/app/views/cas/{sections → sites/sections}/contents/_form_for_content.html.erb +1 -1
  25. data/app/views/cas/{sections → sites/sections}/contents/_form_for_survey.html.erb +1 -1
  26. data/app/views/cas/{sections → sites/sections}/contents/_form_images.html.erb +0 -0
  27. data/app/views/cas/{sections → sites/sections}/contents/edit.html.erb +1 -1
  28. data/app/views/cas/{sections → sites/sections}/contents/index.html.erb +4 -4
  29. data/app/views/cas/{sections → sites/sections}/contents/new.html.erb +1 -1
  30. data/app/views/cas/{sections → sites/sections}/index.html.erb +2 -2
  31. data/app/views/cas/sites/users/_form.html.erb +25 -0
  32. data/app/views/cas/{users → sites/users}/edit.html.erb +0 -0
  33. data/app/views/cas/{users → sites/users}/index.html.erb +3 -3
  34. data/app/views/cas/{users → sites/users}/new.html.erb +0 -0
  35. data/app/views/layouts/cas/application.html.erb +28 -9
  36. data/config/locales/pt-BR.yml +2 -0
  37. data/config/routes.rb +7 -5
  38. data/db/migrate/20170219172958_create_cas_sections.rb +2 -1
  39. data/db/migrate/20171223134308_connects_users_to_sites.rb +13 -0
  40. data/db/migrate/20171223143551_make_site_unique.rb +15 -0
  41. data/lib/cas/cms.rb +1 -0
  42. data/lib/cas/setup.rb +17 -0
  43. data/lib/cas/version.rb +1 -1
  44. metadata +28 -23
  45. data/app/controllers/cas/sections_controller.rb +0 -7
  46. data/app/views/cas/sections/categories/new.html.erb +0 -5
  47. data/app/views/cas/users/_form.html.erb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b88802ff9371e54ee620c776c90e53077379d80
4
- data.tar.gz: c5df9bfa6966724c9c87fcff5d44116a60d95910
3
+ metadata.gz: 77cc9a619a6856b1f1d7fce2d059974c2d6dee9a
4
+ data.tar.gz: f198817ea04364321d99f7ae0e2bf1414367f851
5
5
  SHA512:
6
- metadata.gz: e75b570c8b02a11c99a2239cdb0024107498169ff1fe1152f7c296837c72409a0453d09aaec614b52ad1934e86559af06389ae68311f084ce19a51e2102a7ed4
7
- data.tar.gz: 920b28f837047f0539179e7a3bb0f0e512bae04975a9f8ac3ff69d3ec94ec0b0f48f40da9317627d9ea92396a9a876c48fc83de2dd4834343a9809175a2ce81a
6
+ metadata.gz: 3069cef01247f2cc378ebc1081989c8eaeb36000e63752d765e8c6e76206f7b909421e1e0105526ac69614142616b196e76f70b54a0a2a88c1580f49e4dca6bc
7
+ data.tar.gz: 4cbfd887da3aec99ad33c7dae6cc46edf0f12eabb7ee1e3e7c23357733c56ca9f3cdefe72a9c918872ed50ff9d205fb0a968fc95e2b9c5d16209c56483d0edb7
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  Short description and motivation.
3
3
 
4
4
  ## Usage
5
+
5
6
  How to use my plugin.
6
7
 
7
8
  ## Installation
@@ -5,6 +5,11 @@
5
5
  //= require_self
6
6
 
7
7
  $(document).ready(function() {
8
+ $("#select-site").on("change", function(e) {
9
+ let url = $(this).val();
10
+ window.location = url;
11
+ });
12
+
8
13
  $(".js-tags").selectize({
9
14
  plugins: ['restore_on_backspace', 'remove_button'],
10
15
  delimiter: ',',
@@ -8,12 +8,17 @@ div.input.string, div.input.text
8
8
  border: 1px solid #ddd !important
9
9
  box-shadow: none
10
10
  border-radius: 3px
11
- div.input.string, div.input.text
11
+
12
+ div.input.string,
13
+ div.input.text,
14
+ div.input.string,
15
+ div.input.email,
16
+ div.input.password
17
+ input
18
+ height: 24px
12
19
  input, textarea, select
13
20
  font-size: 1.0em
14
21
  padding: 3px 7px
15
- div.input.string input
16
- height: 24px
17
22
  div.input.content_summary
18
23
  width: 90%
19
24
  textarea
@@ -12,8 +12,12 @@ body > section.grid
12
12
  body > header
13
13
  background: $general-background-color
14
14
  color: white
15
+ padding-left: 10px
15
16
 
16
17
  .top
18
+ .site-selector
19
+ padding-top: 25px
20
+ text-align: center
17
21
  .secondary
18
22
  text-align: right
19
23
  padding-top: 25px
@@ -27,12 +31,12 @@ body > header
27
31
  margin: 0
28
32
  padding: 0
29
33
  list-style: none
30
- margin: 0 15px
34
+ margin: 0
31
35
  li
32
36
  display: table
33
37
  float: left
34
38
  background: white
35
- margin: 0 4px
39
+ margin: 0 8px 0 0
36
40
  border-radius: 4px 4px 0 0
37
41
  &.secondary
38
42
  float: right
@@ -1,4 +1,4 @@
1
- @import url('https://fonts.googleapis.com/css?family=Lato')
1
+ // @import url('https://fonts.googleapis.com/css?family=Lato')
2
2
 
3
3
  body
4
4
  margin: 0
@@ -3,6 +3,8 @@ module Cas
3
3
  protect_from_forgery with: :exception
4
4
  before_action :authenticate_user!
5
5
  before_action :set_current_user
6
+ before_action :set_user_sites
7
+ before_action :set_domain
6
8
 
7
9
  private
8
10
 
@@ -10,8 +12,16 @@ module Cas
10
12
  @current_user = current_user
11
13
  end
12
14
 
15
+ def set_user_sites
16
+ @user_sites = @current_user.sites if @current_user.present?
17
+ end
18
+
13
19
  def set_domain
14
20
  @domain ||= (ENV["DOMAIN"] || request.domain)
21
+
22
+ if @domain.blank? || (ENV["DOMAIN"].blank? && @domain == "localhost")
23
+ @domain = ::Cas::Site.first!.domains.first
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -1,6 +1,8 @@
1
1
  module Cas
2
2
  module Devise
3
3
  class SessionsController < ::Devise::SessionsController
4
+ private
5
+
4
6
  def after_sign_out_path_for(resource_or_scope)
5
7
  cas.root_path
6
8
  end
@@ -0,0 +1,15 @@
1
+ class Cas::Sites::ApplicationController < ::Cas::ApplicationController
2
+ before_action :set_site
3
+
4
+ private
5
+
6
+ def set_site
7
+ if params[:site_id].present?
8
+ @site = ::Cas::Site.find_by!(slug: params[:site_id])
9
+ else
10
+ @site = ::Cas::Site
11
+ .where("cas_sites.domains::text[] && '{#{@domain}}'::text[]")
12
+ .first!
13
+ end
14
+ end
15
+ end
@@ -1,11 +1,11 @@
1
1
  module Cas
2
- class Sections::ApplicationController < ApplicationController
2
+ class Sites::Sections::ApplicationController < Sites::ApplicationController
3
3
  before_action :load_section
4
4
 
5
5
  private
6
6
 
7
7
  def load_section
8
- @section ||= ::Cas::Section.friendly.find(params[:section_id])
8
+ @section ||= @site.sections.friendly.find(params[:section_id])
9
9
  end
10
10
 
11
11
  def scope_content_by_role(model_relation = ::Cas::Content)
@@ -1,7 +1,7 @@
1
1
  require_dependency "cas/application_controller"
2
2
 
3
3
  module Cas
4
- class Sections::CategoriesController < Sections::ApplicationController
4
+ class Sites::Sections::CategoriesController < Sites::Sections::ApplicationController
5
5
  before_action :set_category, only: [:edit, :update, :destroy]
6
6
 
7
7
  def index
@@ -20,7 +20,7 @@ module Cas
20
20
  @category.section = @section
21
21
 
22
22
  if @category.save
23
- redirect_to section_categories_url(@section), notice: 'Categoria salva com sucesso.'
23
+ redirect_to site_section_categories_url(@site, @section), notice: 'Categoria salva com sucesso.'
24
24
  else
25
25
  render :new
26
26
  end
@@ -28,7 +28,7 @@ module Cas
28
28
 
29
29
  def update
30
30
  if @category.update(category_params)
31
- redirect_to section_categories_url(@section), notice: 'Categoria salva com sucesso.'
31
+ redirect_to site_section_categories_url(@site, @section), notice: 'Categoria salva com sucesso.'
32
32
  else
33
33
  render :edit
34
34
  end
@@ -1,7 +1,7 @@
1
1
  require_dependency "cas/application_controller"
2
2
 
3
3
  module Cas
4
- class Sections::ContentsController < Sections::ApplicationController
4
+ class Sites::Sections::ContentsController < Sites::Sections::ApplicationController
5
5
  class FileBelongsToAnotherAttachable < StandardError; end
6
6
  before_action :set_content_type
7
7
 
@@ -33,7 +33,7 @@ module Cas
33
33
  end
34
34
 
35
35
  if success
36
- redirect_to section_contents_url(@section), notice: 'Noticia salva com sucesso.'
36
+ redirect_to site_section_contents_url(@site, @section), notice: 'Noticia salva com sucesso.'
37
37
  else
38
38
  load_categories
39
39
  render :new
@@ -68,7 +68,7 @@ module Cas
68
68
  end
69
69
 
70
70
  if success
71
- redirect_to section_contents_path
71
+ redirect_to site_section_contents_url(@site, @section)
72
72
  else
73
73
  load_categories
74
74
  render :edit
@@ -79,7 +79,7 @@ module Cas
79
79
  @content = scope_content_by_role.friendly.find(params[:id])
80
80
  @content.destroy
81
81
 
82
- redirect_to section_contents_path
82
+ redirect_to site_section_contents_url(@site, @section)
83
83
  end
84
84
 
85
85
  private
@@ -0,0 +1,7 @@
1
+ module Cas
2
+ class Sites::SectionsController < Sites::ApplicationController
3
+ def index
4
+ @sections = @site.sections.all
5
+ end
6
+ end
7
+ end
@@ -1,32 +1,37 @@
1
1
  require_dependency "cas/application_controller"
2
2
 
3
3
  module Cas
4
- class UsersController < ApplicationController
4
+ class Sites::UsersController < Sites::ApplicationController
5
5
  def index
6
- @users = ::Cas::User.order('name ASC')
6
+ @users = @site.users.order('name ASC')
7
7
  end
8
8
 
9
9
  def new
10
10
  @user = ::Cas::User.new
11
+ get_selected_sites
11
12
  end
12
13
 
13
14
  def create
14
15
  @user = ::Cas::User.new(user_params)
15
16
  @user.roles = user_params[:roles]
17
+ @user.site_ids = user_params[:site_ids]
16
18
  if @user.save
17
- redirect_to users_path
19
+ redirect_to site_users_url(@site)
18
20
  else
21
+ get_selected_sites
19
22
  render :new
20
23
  end
21
24
  end
22
25
 
23
26
  def edit
24
27
  @user = ::Cas::User.find(params[:id])
28
+ get_selected_sites
25
29
  end
26
30
 
27
31
  def update
28
32
  @user = ::Cas::User.find(params[:id])
29
33
  success = nil
34
+ @user.site_ids = user_params[:site_ids]
30
35
  if user_params[:password].blank? && user_params[:password_confirmation].blank?
31
36
  without_password = user_params.except(:password, :password_confirmation)
32
37
  success = @user.update_without_password(without_password)
@@ -35,8 +40,9 @@ module Cas
35
40
  end
36
41
 
37
42
  if success
38
- redirect_to users_path
43
+ redirect_to site_users_url(@site)
39
44
  else
45
+ get_selected_sites
40
46
  render 'edit'
41
47
  end
42
48
  end
@@ -44,18 +50,26 @@ module Cas
44
50
  private
45
51
 
46
52
  def user_params
53
+ site_ids = Array.wrap(params[:user][:site_ids]) << @site.id
47
54
  params
48
55
  .require(:user)
49
56
  .permit(
50
57
  :name,
51
58
  :email,
59
+ :site_ids,
52
60
  :password,
53
61
  :password_confirmation,
54
- :roles
62
+ :roles,
55
63
  )
56
64
  .merge!(
57
- roles: [params[:user][:roles]]
65
+ roles: [params[:user][:roles]],
66
+ site_ids: (site_ids).uniq.keep_if(&:present?)
58
67
  )
59
68
  end
69
+
70
+ def get_selected_sites
71
+ @selected_sites = @user.sites.map(&:id)
72
+ @selected_sites << @site.id if @user.new_record?
73
+ end
60
74
  end
61
75
  end
@@ -1,5 +1,10 @@
1
1
  module Cas
2
2
  class Site < ApplicationRecord
3
+ extend ::FriendlyId
4
+ friendly_id :name, use: :slugged
5
+
3
6
  has_many :sections, dependent: :destroy
7
+ has_many :sites_users, class_name: '::Cas::SitesUser'
8
+ has_many :users, through: :sites_users
4
9
  end
5
10
  end
@@ -0,0 +1,7 @@
1
+ module Cas
2
+ class SitesUser < ApplicationRecord
3
+ belongs_to :site
4
+ belongs_to :user
5
+ belongs_to :owner, class_name: '::Cas::User'
6
+ end
7
+ end
@@ -2,23 +2,31 @@ module Cas
2
2
  class User < ApplicationRecord
3
3
  ROLES = %w[admin editor writer].freeze
4
4
 
5
- before_save { self.email = email.to_s.downcase }
5
+ devise :database_authenticatable, #:recoverable,
6
+ :rememberable, :trackable, :validatable, request_keys: [:domain]
7
+
8
+ has_many :contents
9
+ has_many :files, class_name: 'Cas::MediaFile', as: :attachable
10
+ has_many :sites_users, class_name: 'Cas::SitesUser'
11
+ has_many :sites, through: :sites_users
12
+
6
13
  validates :name, presence: true, length: { maximum: 50 }
7
14
  validates :email, presence: true, length: { maximum: 255 },
8
15
  uniqueness: { case_sensitive: false }
9
16
  validates :password, presence: true, length: { minimum: 6 }, on: :create, allow_blank: true
10
17
 
11
- devise :database_authenticatable, #:recoverable,
12
- :rememberable, :trackable, :validatable
13
-
14
- has_many :contents
15
- has_many :files, class_name: Cas::MediaFile, as: :attachable
18
+ before_save { self.email = email.to_s.downcase }
16
19
 
17
20
  def self.find_for_database_authentication(warden_conditions)
18
21
  conditions = warden_conditions.dup
22
+ domain = conditions[:domain]
23
+ domain = ENV["DOMAIN"] if Rails.env.development? && ENV["DOMAIN"].present?
24
+ domain = ::Cas::Site.first.domains.first if domain.to_s =~ /localhost/
19
25
  sql = where(["lower(login) = :value OR lower(email) = :value", {
20
26
  value: conditions[:email].downcase
21
27
  }])
28
+ sql = sql.joins(:sites)
29
+ sql = sql.where("cas_sites.domains::text[] && '{#{domain}}'::text[]")
22
30
  sql.first
23
31
  end
24
32
 
@@ -1,10 +1,10 @@
1
- <%= simple_form_for([@section, category]) do |f| %>
2
- <% if category.errors.any? %>
1
+ <%= simple_form_for([@site, @section, @category]) do |f| %>
2
+ <% if @category.errors.any? %>
3
3
  <div id="error_explanation">
4
4
  <h2>Ocorreram alguns erros:</h2>
5
5
 
6
6
  <ul>
7
- <% category.errors.full_messages.each do |message| %>
7
+ <% @category.errors.full_messages.each do |message| %>
8
8
  <li><%= message %></li>
9
9
  <% end %>
10
10
  </ul>
@@ -2,4 +2,4 @@
2
2
 
3
3
  <%= render 'form', category: @category %>
4
4
 
5
- <%= link_to 'Voltar', section_categories_path(@section) %>
5
+ <%= link_to 'Voltar', site_section_categories_path(@site, @section) %>
@@ -14,7 +14,7 @@
14
14
  <tr>
15
15
  <td>
16
16
  <%= link_to category.name,
17
- cas.edit_section_category_path(@section, category),
17
+ cas.edit_site_section_category_path(@site, @section, category),
18
18
  id: "edit-category-#{category.id}"
19
19
  %>
20
20
  </td>
@@ -25,4 +25,4 @@
25
25
 
26
26
  <br>
27
27
 
28
- <%= link_to 'Nova categoria', cas.new_section_category_path(@section), id: 'new-category' %>
28
+ <%= link_to 'Nova categoria', cas.new_site_section_category_path(@site, @section), id: 'new-category' %>
@@ -0,0 +1,5 @@
1
+ <h1><%= @section.name %>: nova categoria</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Voltar', site_section_categories_path(@site, @section) %>
@@ -1,4 +1,4 @@
1
- <%= simple_form_for ([@section, @content]) do |f| %>
1
+ <%= simple_form_for ([@site, @section, @content]) do |f| %>
2
2
  <% if display_field?(:category) %>
3
3
  <p>
4
4
  <%= f.input :category_id,
@@ -1,4 +1,4 @@
1
- <%= simple_form_for ([@section, @content]) do |f| %>
1
+ <%= simple_form_for ([@site, @section, @content]) do |f| %>
2
2
  <p>
3
3
  <%= f.input :title, as: :string, label: 'Título:' %>
4
4
  </p>
@@ -3,4 +3,4 @@
3
3
 
4
4
  <%= render "form_for_#{@content_type}" %>
5
5
 
6
- <%= link_to 'Voltar', section_contents_path %>
6
+ <%= link_to 'Voltar', site_section_content_path %>
@@ -4,13 +4,13 @@
4
4
  </div>
5
5
  <div class="col-1-2 section-options">
6
6
  <% if Cas::SectionConfig.new(@section).form_has_field?(:category) %>
7
- <%= link_to "Categorias", section_categories_path(@section), id: 'manage-categories' %>
7
+ <%= link_to "Categorias", site_section_categories_path(@site, @section), id: 'manage-categories' %>
8
8
  <% end %>
9
9
  </div>
10
10
  </div>
11
11
 
12
12
  <%= link_to 'Novo conteúdo',
13
- new_section_content_path(@section.id),
13
+ new_site_section_content_path(@site, @section),
14
14
  id: 'new-content' %>
15
15
 
16
16
  <br />
@@ -47,7 +47,7 @@
47
47
 
48
48
  <% if column_no == 1 %>
49
49
  <%= link_to value,
50
- edit_section_content_path(@section.id, content),
50
+ edit_site_section_content_path(@site, @section, content),
51
51
  id: "edit-content-#{content.id}" %>
52
52
  <% else %>
53
53
  <%= value %>
@@ -57,7 +57,7 @@
57
57
  </td>
58
58
  <% end %>
59
59
  <td>
60
- <%= link_to 'Excluir', section_content_path(@section.id, content),
60
+ <%= link_to 'Excluir', site_section_content_path(@site, @section, content),
61
61
  method: :delete,
62
62
  data: { confirm: 'Tem certeza?' },
63
63
  id: "delete-content-#{content.id}" %>
@@ -2,4 +2,4 @@
2
2
 
3
3
  <%= render "form_for_#{@content_type}" %>
4
4
 
5
- <%= link_to 'Voltar', section_contents_path %>
5
+ <%= link_to 'Voltar', site_section_contents_path(@site, @section) %>
@@ -11,10 +11,10 @@
11
11
  <tr id="section-<%= section.id %>">
12
12
  <td><%= section.name %></td>
13
13
  <td>
14
- <%= link_to 'Novo', new_section_content_path(section), id: "new-content-#{section.id}" %>
14
+ <%= link_to 'Novo', new_site_section_content_path(@site, section), id: "new-content-#{section.id}" %>
15
15
  &nbsp;
16
16
  &nbsp;
17
- <%= link_to 'Gerenciar', section_contents_path(section), id: "manage-section-#{section.id}" %>
17
+ <%= link_to 'Gerenciar', site_section_contents_path(@site, section), id: "manage-section-#{section.id}" %>
18
18
  </td>
19
19
  </tr>
20
20
  <% end %>
@@ -0,0 +1,25 @@
1
+ <%= simple_form_for [@site, @user] do |f| %>
2
+ <%= f.input :name %><br />
3
+ <%= f.input :email %><br />
4
+
5
+ <% if @current_user.admin? %>
6
+ <%= f.collection_check_boxes(
7
+ :site_ids,
8
+ @current_user.sites,
9
+ :id,
10
+ :name,
11
+ checked: @selected_sites
12
+ ) do |s| %>
13
+ <%= s.check_box(disabled: (s.value == @site.id), id: "site-id-#{s.value}") %>
14
+ <%= s.text %>
15
+ <% end %>
16
+ <% end %>
17
+
18
+ <% if current_user.admin? %>
19
+ <%= f.collection_select :roles, Cas::User::ROLES, :to_s, :humanize %></p>
20
+ <% end %>
21
+ <%= f.input :password, required: false %><br />
22
+ <%= f.input :password_confirmation %><br />
23
+
24
+ <%= f.button :submit, id: "save-form" %><br />
25
+ <% end %>
@@ -1,12 +1,12 @@
1
1
  <div class="grid">
2
2
  <div class="col-1-2">
3
- <h1>Lista Usuários</h1>
3
+ <h1>Usuários</h1>
4
4
  </div>
5
5
  <div class="col-1-2 section-options">
6
6
  </div>
7
7
  </div>
8
8
 
9
- <%= link_to "Novo Usuário", new_user_path if current_user.admin? %>
9
+ <%= link_to "Novo Usuário", new_site_user_path(@site) if current_user.admin? %>
10
10
 
11
11
  <br />
12
12
  <br />
@@ -24,7 +24,7 @@
24
24
  <tr id="user-<%= user.id %>">
25
25
  <td>
26
26
  <%= link_to user.name,
27
- edit_user_path(user),
27
+ edit_site_user_path(@site, user),
28
28
  id: "edit-user-#{user.id}" %>
29
29
  </td>
30
30
  <td><%= user.roles.join(", ") %></td>
@@ -26,34 +26,53 @@
26
26
 
27
27
  <%= csrf_meta_tags %>
28
28
  </head>
29
- <body>
29
+ <body class="<%= "site-#{@site.id}" if @current_user.present? %>">
30
30
 
31
31
  <header>
32
32
  <div class="grid top">
33
- <div class="col-1-2">
33
+ <div class="mobile-col-1-1 col-1-3">
34
34
  <h1>
35
35
  Admin
36
36
  </h1>
37
37
  </div>
38
- <div class="col-1-2 secondary">
39
- <% if user_signed_in? %>
38
+
39
+ <% if user_signed_in? %>
40
+ <div class="mobile-col-1-1 col-1-3 site-selector">
41
+ <% if @user_sites.count <= 1 %>
42
+ <%= @user_sites[0].name %> (<%= @user_sites[0].domains.join(", ") %>)
43
+ <% else %>
44
+ <select id="select-site">
45
+ <% @user_sites.each do |site| %>
46
+ <% selected = site.id == @site.id %>
47
+ <option
48
+ value="<%= site_sections_path(site) %>"
49
+ <%= 'selected="selected"' if selected %>
50
+ >
51
+ <%= site.name %>
52
+ (<%= site.domains.join(", ") %>)
53
+ </option>
54
+ <% end %>
55
+ </select>
56
+ <% end %>
57
+ </div>
58
+ <div class="mobile-col-1-1 col-1-3 secondary">
40
59
  <span class="profile">
41
- <%= link_to current_user.name, cas.edit_user_path(current_user), id: "edit-profile"%>
60
+ <%= link_to "Minha conta", cas.edit_site_user_path(@site, current_user), id: "edit-profile"%>
42
61
  </span>
43
62
  <span class="sign-out"%>
44
63
  <%= link_to "Sair", cas.destroy_user_session_path, method: :delete %>
45
64
  </span>
46
- <% end %>
47
- </div>
65
+ </div>
66
+ <% end %>
48
67
  </div>
49
68
 
50
69
  <nav class="grid">
51
70
  <ul>
52
71
  <% if user_signed_in? %>
53
- <li><%= link_to "Conteúdo", cas.root_path %></li>
72
+ <li><%= link_to "Conteúdo", cas.site_sections_path(@site) %></li>
54
73
  <% end %>
55
74
  <% if user_signed_in? && current_user.admin? %>
56
- <li><%= link_to "Pessoas", cas.users_path, id: "list-people" %></li>
75
+ <li><%= link_to "Pessoas", cas.site_users_path(@site), id: "list-people" %></li>
57
76
  <% end %>
58
77
  </ul>
59
78
  </nav>
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  pt-BR:
3
3
  activerecord:
4
+ models:
5
+ cas/user: 'Usuário'
4
6
  attributes:
5
7
  cas/user:
6
8
  name: 'Nome'
@@ -14,11 +14,13 @@ Cas::Engine.routes.draw do
14
14
  controllers: { sessions: "cas/devise/sessions" },
15
15
  skip: :registrations
16
16
 
17
- resources :users, controller: 'users'
17
+ resources :sites, only: [:index] do
18
+ resources :users, controller: 'sites/users'
18
19
 
19
- resources :sections, only: [:index] do
20
- resources :contents, controller: 'sections/contents'
21
- resources :categories, controller: 'sections/categories'
20
+ resources :sections, only: [:index], controller: 'sites/sections' do
21
+ resources :contents, controller: 'sites/sections/contents'
22
+ resources :categories, controller: 'sites/sections/categories'
23
+ end
22
24
  end
23
25
 
24
26
  # used by tinymce editor
@@ -27,5 +29,5 @@ Cas::Engine.routes.draw do
27
29
  resources :files, only: [:create, :destroy]
28
30
  end
29
31
 
30
- root 'sections#index'
32
+ root 'sites/sections#index'
31
33
  end
@@ -7,6 +7,7 @@ class CreateCasSections < ActiveRecord::Migration[5.0]
7
7
 
8
8
  t.timestamps
9
9
  end
10
- add_index :cas_sections, :site_id
10
+
11
+ add_index :cas_sections, :site_id
11
12
  end
12
13
  end
@@ -0,0 +1,13 @@
1
+ class ConnectsUsersToSites < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :cas_sites_users, id: :uuid do |t|
4
+ t.column :user_id, :uuid, null: false
5
+ t.column :site_id, :uuid, null: false
6
+ t.boolean :author_id, :uuid
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :cas_sites_users, [:site_id, :user_id]
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class MakeSiteUnique < ActiveRecord::Migration[5.0]
2
+ def up
3
+ remove_index :cas_sites, :slug
4
+ remove_index :cas_sites, :name
5
+ add_index :cas_sites, :name, unique: true
6
+ add_index :cas_sites, :slug, unique: true
7
+ end
8
+
9
+ def down
10
+ remove_index :cas_sites, :slug
11
+ remove_index :cas_sites, :name
12
+ add_index :cas_sites, :slug, unique: false
13
+ add_index :cas_sites, :name, unique: true
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require_relative '../cas'
@@ -26,6 +26,23 @@ module Cas
26
26
  )
27
27
  end
28
28
  end
29
+
30
+ if superadmins_emails_or_logins = config["config"]["superadmins"]
31
+ updated_users = []
32
+ superadmins_emails_or_logins.each do |email_or_login|
33
+ user = ::Cas::User.where(
34
+ 'cas_users.email = :value OR cas_users.login = :value',
35
+ value: email_or_login
36
+ ).first
37
+
38
+ if user.present?
39
+ unless updated_users.include?(user.id)
40
+ user.update!(sites: ::Cas::Site.all)
41
+ end
42
+ updated_users << user.id
43
+ end
44
+ end
45
+ end
29
46
  end
30
47
  end
31
48
 
@@ -1,3 +1,3 @@
1
1
  module Cas
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cas-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre de Oliveira
@@ -445,11 +445,12 @@ files:
445
445
  - app/controllers/cas/application_controller.rb
446
446
  - app/controllers/cas/devise/sessions_controller.rb
447
447
  - app/controllers/cas/file_uploads_controller.rb
448
- - app/controllers/cas/sections/application_controller.rb
449
- - app/controllers/cas/sections/categories_controller.rb
450
- - app/controllers/cas/sections/contents_controller.rb
451
- - app/controllers/cas/sections_controller.rb
452
- - app/controllers/cas/users_controller.rb
448
+ - app/controllers/cas/sites/application_controller.rb
449
+ - app/controllers/cas/sites/sections/application_controller.rb
450
+ - app/controllers/cas/sites/sections/categories_controller.rb
451
+ - app/controllers/cas/sites/sections/contents_controller.rb
452
+ - app/controllers/cas/sites/sections_controller.rb
453
+ - app/controllers/cas/sites/users_controller.rb
453
454
  - app/helpers/cas/application_helper.rb
454
455
  - app/helpers/cas/form_helper.rb
455
456
  - app/jobs/cas/application_job.rb
@@ -462,27 +463,28 @@ files:
462
463
  - app/models/cas/media_file.rb
463
464
  - app/models/cas/section.rb
464
465
  - app/models/cas/site.rb
466
+ - app/models/cas/sites_user.rb
465
467
  - app/models/cas/user.rb
466
468
  - app/uploaders/file_uploader.rb
467
469
  - app/views/cas/devise/sessions/new.html.erb
468
- - app/views/cas/sections/categories/_form.html.erb
469
- - app/views/cas/sections/categories/edit.html.erb
470
- - app/views/cas/sections/categories/index.html.erb
471
- - app/views/cas/sections/categories/new.html.erb
472
- - app/views/cas/sections/contents/_form_attachments.html.erb
473
- - app/views/cas/sections/contents/_form_attachments_template.html.erb
474
- - app/views/cas/sections/contents/_form_for_content.html.erb
475
- - app/views/cas/sections/contents/_form_for_survey.html.erb
476
- - app/views/cas/sections/contents/_form_images.html.erb
477
- - app/views/cas/sections/contents/edit.html.erb
478
- - app/views/cas/sections/contents/index.html.erb
479
- - app/views/cas/sections/contents/new.html.erb
480
- - app/views/cas/sections/index.html.erb
481
470
  - app/views/cas/shared/_error_messages.html.erb
482
- - app/views/cas/users/_form.html.erb
483
- - app/views/cas/users/edit.html.erb
484
- - app/views/cas/users/index.html.erb
485
- - app/views/cas/users/new.html.erb
471
+ - app/views/cas/sites/sections/categories/_form.html.erb
472
+ - app/views/cas/sites/sections/categories/edit.html.erb
473
+ - app/views/cas/sites/sections/categories/index.html.erb
474
+ - app/views/cas/sites/sections/categories/new.html.erb
475
+ - app/views/cas/sites/sections/contents/_form_attachments.html.erb
476
+ - app/views/cas/sites/sections/contents/_form_attachments_template.html.erb
477
+ - app/views/cas/sites/sections/contents/_form_for_content.html.erb
478
+ - app/views/cas/sites/sections/contents/_form_for_survey.html.erb
479
+ - app/views/cas/sites/sections/contents/_form_images.html.erb
480
+ - app/views/cas/sites/sections/contents/edit.html.erb
481
+ - app/views/cas/sites/sections/contents/index.html.erb
482
+ - app/views/cas/sites/sections/contents/new.html.erb
483
+ - app/views/cas/sites/sections/index.html.erb
484
+ - app/views/cas/sites/users/_form.html.erb
485
+ - app/views/cas/sites/users/edit.html.erb
486
+ - app/views/cas/sites/users/index.html.erb
487
+ - app/views/cas/sites/users/new.html.erb
486
488
  - app/views/layouts/cas/application.html.erb
487
489
  - config/initializers/acts_as_taggable.rb
488
490
  - config/initializers/devise.rb
@@ -522,7 +524,10 @@ files:
522
524
  - db/migrate/20170830000002_use_uuid_with_acts_as_taggable_references.rb
523
525
  - db/migrate/20170919181809_pageviews_default_to_zero.rb
524
526
  - db/migrate/20171201191059_add_domains_to_cas_site.rb
527
+ - db/migrate/20171223134308_connects_users_to_sites.rb
528
+ - db/migrate/20171223143551_make_site_unique.rb
525
529
  - lib/cas.rb
530
+ - lib/cas/cms.rb
526
531
  - lib/cas/config.rb
527
532
  - lib/cas/engine.rb
528
533
  - lib/cas/form_field.rb
@@ -1,7 +0,0 @@
1
- module Cas
2
- class SectionsController < ApplicationController
3
- def index
4
- @sections = Section.all
5
- end
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- <h1><%= @section.name %>: nova categoria</h1>
2
-
3
- <%= render 'form', category: @category %>
4
-
5
- <%= link_to 'Voltar', section_categories_path(@section) %>
@@ -1,11 +0,0 @@
1
- <%= simple_form_for(@user) do |f| %>
2
- <%= f.input :name %><br />
3
- <%= f.input :email %><br />
4
- <% if current_user.admin? %>
5
- <%= f.collection_select :roles, Cas::User::ROLES, :to_s, :humanize %></p>
6
- <% end %>
7
- <%= f.input :password, required: false %><br />
8
- <%= f.input :password_confirmation %><br />
9
-
10
- <%= f.button :submit, id: "save-form" %><br />
11
- <% end %>