-
Notifications
You must be signed in to change notification settings - Fork 1
Add migration alter cas_users to cas_people #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preciso do
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👆 |
||
|
|
||
| before_validation :set_media_type | ||
| before_save :set_image_as_unique_cover | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module Cas | ||
| class PeopleSite < ApplicationRecord | ||
| belongs_to :site | ||
| belongs_to :person | ||
| belongs_to :owner, class_name: '::Cas::Person' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pensando melhor, acho que o nome Acho que o melhor nome seria
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ |
||
|
|
||
| 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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has_many :people_sites, creio.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ |
||
| has_many :sites, through: :people_site | ||
| has_many :activities, as: :subject | ||
|
|
||
| validates :name, presence: true, length: { maximum: 50 } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ |
||
| has_many :people, through: :people_site | ||
| end | ||
| end | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <div class="grid"> | ||
| <div class="col-1-2"> | ||
| <h1>Pessoas</h1> | ||
| </div> | ||
| <div class="col-1-2 section-options"> | ||
| </div> | ||
| </div> | ||
|
|
||
| <%= link_to "Nova Pessoa", new_site_person_path(@site) if current_user.admin? %> | ||
|
|
||
| <br /> | ||
| <br /> | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Nome</th> | ||
| <th></th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| <tbody> | ||
| <% @people.each do |person| %> | ||
| <tr id="person-<%= person.id %>"> | ||
| <td> | ||
| <%= link_to person.name, | ||
| edit_site_person_url(@site, person), | ||
| id: "edit-person-#{person.id}" %> | ||
| </td> | ||
| <td><%= person.roles.join(", ") %></td> | ||
| </tr> | ||
| <% end %> | ||
| </tbody> | ||
| </table> |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisa colocar de volta a string em
class_namepra que a classe só seja executada quando necessária (lazy evaluation) e os::(pra evitar conflito de namespace)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faltou aqui