diff --git a/app/controllers/cas/application_controller.rb b/app/controllers/cas/application_controller.rb
index 2424355..0110402 100644
--- a/app/controllers/cas/application_controller.rb
+++ b/app/controllers/cas/application_controller.rb
@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :set_current_user
- before_action :set_user_sites
+ before_action :set_person_sites
before_action :set_domain
before_action :set_site
@@ -13,8 +13,8 @@ def set_current_user
@current_user = current_user
end
- def set_user_sites
- @user_sites = @current_user.sites if @current_user.present?
+ def set_person_sites
+ @person_sites = @current_user.sites if @current_user.present?
end
def set_domain
diff --git a/app/controllers/cas/sites/people_controller.rb b/app/controllers/cas/sites/people_controller.rb
new file mode 100644
index 0000000..fb50cc0
--- /dev/null
+++ b/app/controllers/cas/sites/people_controller.rb
@@ -0,0 +1,75 @@
+require_dependency "cas/application_controller"
+
+module Cas
+ class Sites::PeopleController < Sites::ApplicationController
+ def index
+ @people = @site.people.order('name ASC')
+ end
+
+ def new
+ @person = ::Cas::Person.new
+ get_selected_sites
+ end
+
+ def create
+ @person = ::Cas::Person.new(person_params)
+ @person.roles = person_params[:roles]
+ @person.site_ids = person_params[:site_ids]
+ if @person.save
+ redirect_to site_people_url(@site)
+ else
+ get_selected_sites
+ render :new
+ end
+ end
+
+ def edit
+ @person = ::Cas::Person.find(params[:id])
+ get_selected_sites
+ end
+
+ def update
+ @person = ::Cas::Person.find(params[:id])
+ success = nil
+ @person.site_ids = person_params[:site_ids]
+ if person_params[:password].blank? && person_params[:password_confirmation].blank?
+ without_password = person_params.except(:password, :password_confirmation)
+ success = @person.update_without_password(without_password)
+ else
+ success = @person.update_attributes(person_params)
+ end
+
+ if success
+ redirect_to site_people_url(@site)
+ else
+ get_selected_sites
+ render 'edit'
+ end
+ end
+
+ private
+
+ def person_params
+ site_ids = Array.wrap(params[:person][:site_ids]) << @site.id
+ params
+ .require(:person)
+ .permit(
+ :name,
+ :email,
+ :site_ids,
+ :password,
+ :password_confirmation,
+ :roles,
+ )
+ .merge!(
+ roles: [params[:person][:roles]],
+ site_ids: (site_ids).uniq.keep_if(&:present?)
+ )
+ end
+
+ def get_selected_sites
+ @selected_sites = @person.sites.map(&:id)
+ @selected_sites << @site.id if @person.new_record?
+ end
+ end
+end
diff --git a/app/controllers/cas/sites/sections/contents_controller.rb b/app/controllers/cas/sites/sections/contents_controller.rb
index aff189c..85a7e0d 100644
--- a/app/controllers/cas/sites/sections/contents_controller.rb
+++ b/app/controllers/cas/sites/sections/contents_controller.rb
@@ -25,7 +25,7 @@ def create
@content.section_id = @section.id
@content.tag_list = content_params[:tag_list] if content_params[:tag_list]
success = @content.save!
- ::Cas::Activity.create!(user: current_user, site: @site, subject: @content, event_name: 'create')
+ ::Cas::Activity.create!(person: current_user, site: @site, subject: @content, event_name: 'create')
associate_files(@content, :images)
associate_files(@content, :attachments)
end
@@ -63,7 +63,7 @@ def update
success = @content.update!(content_params)
associate_files(@content, :images)
associate_files(@content, :attachments)
- ::Cas::Activity.create!(user: current_user, site: @site, subject: @content, event_name: 'update')
+ ::Cas::Activity.create!(person: current_user, site: @site, subject: @content, event_name: 'update')
end
rescue ActiveRecord::RecordInvalid
success = nil
diff --git a/app/controllers/cas/sites/users_controller.rb b/app/controllers/cas/sites/users_controller.rb
deleted file mode 100644
index c0a07f7..0000000
--- a/app/controllers/cas/sites/users_controller.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-require_dependency "cas/application_controller"
-
-module Cas
- class Sites::UsersController < Sites::ApplicationController
- def index
- @users = @site.users.order('name ASC')
- end
-
- def new
- @user = ::Cas::User.new
- get_selected_sites
- end
-
- def create
- @user = ::Cas::User.new(user_params)
- @user.roles = user_params[:roles]
- @user.site_ids = user_params[:site_ids]
- if @user.save
- redirect_to site_users_url(@site)
- else
- get_selected_sites
- render :new
- end
- end
-
- def edit
- @user = ::Cas::User.find(params[:id])
- get_selected_sites
- end
-
- def update
- @user = ::Cas::User.find(params[:id])
- success = nil
- @user.site_ids = user_params[:site_ids]
- if user_params[:password].blank? && user_params[:password_confirmation].blank?
- without_password = user_params.except(:password, :password_confirmation)
- success = @user.update_without_password(without_password)
- else
- success = @user.update_attributes(user_params)
- end
-
- if success
- redirect_to site_users_url(@site)
- else
- get_selected_sites
- render 'edit'
- end
- end
-
- private
-
- def user_params
- site_ids = Array.wrap(params[:user][:site_ids]) << @site.id
- params
- .require(:user)
- .permit(
- :name,
- :email,
- :site_ids,
- :password,
- :password_confirmation,
- :roles,
- )
- .merge!(
- roles: [params[:user][:roles]],
- site_ids: (site_ids).uniq.keep_if(&:present?)
- )
- end
-
- def get_selected_sites
- @selected_sites = @user.sites.map(&:id)
- @selected_sites << @site.id if @user.new_record?
- end
- end
-end
diff --git a/app/models/cas/activity.rb b/app/models/cas/activity.rb
index 60cac7e..6581f21 100644
--- a/app/models/cas/activity.rb
+++ b/app/models/cas/activity.rb
@@ -1,7 +1,7 @@
module Cas
class Activity < ApplicationRecord
belongs_to :site
- belongs_to :user
+ belongs_to :person
belongs_to :subject, polymorphic: true
end
end
diff --git a/app/models/cas/content.rb b/app/models/cas/content.rb
index 969c4c0..7719051 100644
--- a/app/models/cas/content.rb
+++ b/app/models/cas/content.rb
@@ -11,8 +11,8 @@ class Content < ApplicationRecord
belongs_to :section
has_one :site, through: :section
belongs_to :category
- belongs_to :author, class_name: "::Cas::User"
- has_many :images, ->{ where(media_type: :image).order("cas_media_files.order ASC") }, class_name: "::Cas::MediaFile", as: :attachable, dependent: :destroy
+ belongs_to :author, class_name: "::Cas::Person"
+ has_many :images, ->{ where(media_type: :image).order("cas_media_files.order ASC") }, class_name: Cas::MediaFile, as: :attachable, dependent: :destroy
has_many :attachments, ->{ where(media_type: :attachment).order("cas_media_files.order ASC") }, class_name: "::Cas::MediaFile", as: :attachable, dependent: :destroy
has_many :activities, as: :subject
has_one :cover_image, ->{ where(media_type: :image, cover: true) }, class_name: "::Cas::MediaFile", as: :attachable
diff --git a/app/models/cas/media_file.rb b/app/models/cas/media_file.rb
index 75567de..591ffbb 100644
--- a/app/models/cas/media_file.rb
+++ b/app/models/cas/media_file.rb
@@ -6,7 +6,7 @@ class UnknownPath < StandardError; end
class UnknownFileService < StandardError; end
belongs_to :attachable, polymorphic: true
- belongs_to :author, class_name: "::Cas::User"
+ belongs_to :author, class_name: "Cas::Person"
before_validation :set_media_type
before_save :set_image_as_unique_cover
diff --git a/app/models/cas/people_site.rb b/app/models/cas/people_site.rb
new file mode 100644
index 0000000..8d19b57
--- /dev/null
+++ b/app/models/cas/people_site.rb
@@ -0,0 +1,7 @@
+module Cas
+ class PeopleSite < ApplicationRecord
+ belongs_to :site
+ belongs_to :person
+ belongs_to :owner, class_name: '::Cas::Person'
+ end
+end
diff --git a/app/models/cas/user.rb b/app/models/cas/person.rb
similarity index 83%
rename from app/models/cas/user.rb
rename to app/models/cas/person.rb
index 4041d38..5cfccfd 100644
--- a/app/models/cas/user.rb
+++ b/app/models/cas/person.rb
@@ -1,14 +1,14 @@
module Cas
- class User < ApplicationRecord
- ROLES = %w[admin editor writer].freeze
+ class Person < ApplicationRecord
+ ROLES = %w[admin editor writer visitor].freeze
devise :database_authenticatable, #:recoverable,
:rememberable, :trackable, :validatable, request_keys: [:domain]
has_many :contents
- has_many :files, class_name: '::Cas::MediaFile', as: :attachable
- has_many :sites_users, class_name: '::Cas::SitesUser'
- has_many :sites, through: :sites_users
+ has_many :files, class_name: 'Cas::MediaFile', as: :attachable
+ has_many :people_site, class_name: 'Cas::PeopleSite'
+ has_many :sites, through: :people_site
has_many :activities, as: :subject
validates :name, presence: true, length: { maximum: 50 }
diff --git a/app/models/cas/site.rb b/app/models/cas/site.rb
index b45fd4a..318727f 100644
--- a/app/models/cas/site.rb
+++ b/app/models/cas/site.rb
@@ -4,7 +4,7 @@ class Site < ApplicationRecord
friendly_id :name, use: :slugged
has_many :sections, dependent: :destroy
- has_many :sites_users, class_name: '::Cas::SitesUser'
- has_many :users, through: :sites_users
+ has_many :people_site, class_name: '::Cas::PeopleSite'
+ has_many :people, through: :people_site
end
end
diff --git a/app/models/cas/sites_user.rb b/app/models/cas/sites_user.rb
deleted file mode 100644
index c026700..0000000
--- a/app/models/cas/sites_user.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Cas
- class SitesUser < ApplicationRecord
- belongs_to :site
- belongs_to :user
- belongs_to :owner, class_name: '::Cas::User'
- end
-end
diff --git a/app/views/cas/activities/index.html.erb b/app/views/cas/activities/index.html.erb
index 71aea0b..57d70cc 100644
--- a/app/views/cas/activities/index.html.erb
+++ b/app/views/cas/activities/index.html.erb
@@ -24,7 +24,7 @@
<%= activity.site.name %>
| <%= section.name %> |
diff --git a/app/views/cas/sites/users/index.html.erb b/app/views/cas/sites/users/index.html.erb
deleted file mode 100644
index e962e77..0000000
--- a/app/views/cas/sites/users/index.html.erb
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-<%= link_to "Novo Usuário", new_site_user_path(@site) if current_user.admin? %>
-
-
-
-
-
-
-
- | Nome |
- |
-
-
-
-
- <% @users.each do |user| %>
-
- |
- <%= link_to user.name,
- edit_site_user_path(@site, user),
- id: "edit-user-#{user.id}" %>
- |
- <%= user.roles.join(", ") %> |
-
- <% end %>
-
-
diff --git a/app/views/layouts/cas/application.html.erb b/app/views/layouts/cas/application.html.erb
index a67da40..28b94c4 100644
--- a/app/views/layouts/cas/application.html.erb
+++ b/app/views/layouts/cas/application.html.erb
@@ -38,11 +38,11 @@
<% if user_signed_in? %>
- <% if @user_sites.count <= 1 %>
- <%= @user_sites[0].name %> (<%= @user_sites[0].domains.join(", ") %>)
+ <% if @person_sites.count <= 1 %>
+ <%= @person_sites[0].name %> (<%= @person_sites[0].domains.join(", ") %>)
<% else %>
|