mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
migrate projects to statistic_profile
This commit is contained in:
parent
35da65b686
commit
cfd33c3a52
@ -257,6 +257,7 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P
|
||||
/* PRIVATE STATIC CONSTANTS */
|
||||
|
||||
// Number of projects added to the page when the user clicks on 'load more projects'
|
||||
// -- dependency in app/models/project.rb
|
||||
const PROJECTS_PER_PAGE = 16;
|
||||
|
||||
/* PUBLIC SCOPE */
|
||||
|
@ -14,11 +14,11 @@
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" translate>{{ 'trainings' }}</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="hidden" name="user[training_ids][]" value="" />
|
||||
<input type="hidden" name="user[statistic_profile_attributes][training_ids][]" value="" />
|
||||
<ui-select multiple ng-model="user.training_ids" class="form-control">
|
||||
<ui-select-match>
|
||||
<span ng-bind="$item.name"></span>
|
||||
<input type="hidden" name="user[training_ids][]" value="{{$item.id}}" />
|
||||
<input type="hidden" name="user[statistic_profile_attributes][training_ids][]" value="{{$item.id}}" />
|
||||
</ui-select-match>
|
||||
<ui-select-choices ui-disable-choice="t.disabled" repeat="t.id as t in (trainings | filter: $select.search)">
|
||||
<span ng-bind-html="t.name | highlight: $select.search"></span>
|
||||
|
@ -203,7 +203,7 @@ class API::MembersController < API::ApiController
|
||||
|
||||
elsif current_user.admin?
|
||||
params.require(:user).permit(:username, :email, :password, :password_confirmation, :is_allow_contact, :is_allow_newsletter, :group_id,
|
||||
training_ids: [], tag_ids: [],
|
||||
tag_ids: [],
|
||||
profile_attributes: [:id, :first_name, :last_name, :phone, :interest, :software_mastered, :website, :job,
|
||||
:facebook, :twitter, :google_plus, :viadeo, :linkedin, :instagram, :youtube, :vimeo,
|
||||
:dailymotion, :github, :echosciences, :pinterest, :lastfm, :flickr,
|
||||
@ -213,7 +213,7 @@ class API::MembersController < API::ApiController
|
||||
address_attributes: %i[id address],
|
||||
organization_attributes: [:id, :name, address_attributes: %i[id address]]
|
||||
],
|
||||
statistic_profile_attributes: %i[id gender birthday])
|
||||
statistic_profile_attributes: [:id, :gender, :birthday, training_ids: []])
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ class API::ProjectsController < API::ApiController
|
||||
end
|
||||
|
||||
def create
|
||||
@project = Project.new(project_params.merge(author_id: current_user.id))
|
||||
@project = Project.new(project_params.merge(author_statistic_profile_id: current_user.statistic_profile.id))
|
||||
if @project.save
|
||||
render :show, status: :created, location: @project
|
||||
else
|
||||
@ -71,8 +71,7 @@ class API::ProjectsController < API::ApiController
|
||||
end
|
||||
|
||||
def project_params
|
||||
params.require(:project).permit(:name, :description, :tags, :machine_ids, :component_ids, :theme_ids, :licence_id,
|
||||
:author_id, :licence_id, :state,
|
||||
params.require(:project).permit(:name, :description, :tags, :machine_ids, :component_ids, :theme_ids, :licence_id, :licence_id, :state,
|
||||
user_ids: [], machine_ids: [], component_ids: [], theme_ids: [],
|
||||
project_image_attributes: [:attachment],
|
||||
project_caos_attributes: %i[id attachment _destroy],
|
||||
|
@ -1,3 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Availability stores time slots that are available to reservation for an associated reservable
|
||||
# Eg. a 3D printer will be reservable on thursday from 9 to 11 pm
|
||||
# Availabilities may be subdivided into Slots (of 1h), for some types of reservables (eg. Machine)
|
||||
class Availability < ActiveRecord::Base
|
||||
|
||||
# elastic initialisations
|
||||
@ -87,9 +92,7 @@ class Availability < ActiveRecord::Base
|
||||
def title(filter = {})
|
||||
case available_type
|
||||
when 'machines'
|
||||
if filter[:machine_ids]
|
||||
return machines.to_ary.delete_if { |m| !filter[:machine_ids].include?(m.id) }.map(&:name).join(' - ')
|
||||
end
|
||||
return machines.to_ary.delete_if { |m| !filter[:machine_ids].include?(m.id) }.map(&:name).join(' - ') if filter[:machine_ids]
|
||||
|
||||
machines.map(&:name).join(' - ')
|
||||
when 'event'
|
||||
@ -134,13 +137,13 @@ class Availability < ActiveRecord::Base
|
||||
json['hours_duration'] = (end_at - start_at) / (60 * 60)
|
||||
json['subType'] = case available_type
|
||||
when 'machines'
|
||||
machines_availabilities.map{ |ma| ma.machine.friendly_id }
|
||||
machines_availabilities.map { |ma| ma.machine.friendly_id }
|
||||
when 'training'
|
||||
trainings_availabilities.map{ |ta| ta.training.friendly_id }
|
||||
trainings_availabilities.map { |ta| ta.training.friendly_id }
|
||||
when 'event'
|
||||
[event.category.friendly_id]
|
||||
when 'space'
|
||||
spaces_availabilities.map{ |sa| sa.space.friendly_id }
|
||||
spaces_availabilities.map { |sa| sa.space.friendly_id }
|
||||
else
|
||||
[]
|
||||
end
|
||||
@ -156,7 +159,9 @@ class Availability < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def should_be_associated
|
||||
errors.add(:machine_ids, I18n.t('availabilities.must_be_associated_with_at_least_1_machine')) if available_type == 'machines' && machine_ids.count == 0
|
||||
return unless available_type == 'machines' && machine_ids.count.zero?
|
||||
|
||||
errors.add(:machine_ids, I18n.t('availabilities.must_be_associated_with_at_least_1_machine'))
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,3 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Project is the documentation about an object built by a fab-user
|
||||
# It can describe the steps taken by the fab-user to build his object, provide photos, description, attached CAO files, etc.
|
||||
class Project < ActiveRecord::Base
|
||||
include AASM
|
||||
include NotifyWith::NotificationAttachedObject
|
||||
@ -9,7 +13,8 @@ class Project < ActiveRecord::Base
|
||||
document_type 'projects'
|
||||
|
||||
# kaminari
|
||||
paginates_per 12 # dependency in projects.coffee
|
||||
# -- dependency in app/assets/javascripts/controllers/projects.js.erb
|
||||
paginates_per 16
|
||||
|
||||
# friendlyId
|
||||
extend FriendlyId
|
||||
@ -20,15 +25,15 @@ class Project < ActiveRecord::Base
|
||||
has_many :project_caos, as: :viewable, dependent: :destroy
|
||||
accepts_nested_attributes_for :project_caos, allow_destroy: true, reject_if: :all_blank
|
||||
|
||||
has_and_belongs_to_many :machines, join_table: :projects_machines
|
||||
has_and_belongs_to_many :spaces, join_table: :projects_spaces
|
||||
has_and_belongs_to_many :components, join_table: :projects_components
|
||||
has_and_belongs_to_many :themes, join_table: :projects_themes
|
||||
has_and_belongs_to_many :machines, join_table: 'projects_machines'
|
||||
has_and_belongs_to_many :spaces, join_table: 'projects_spaces'
|
||||
has_and_belongs_to_many :components, join_table: 'projects_components'
|
||||
has_and_belongs_to_many :themes, join_table: 'projects_themes'
|
||||
|
||||
has_many :project_users, dependent: :destroy
|
||||
has_many :users, through: :project_users
|
||||
|
||||
belongs_to :author, foreign_key: :author_id, class_name: 'User'
|
||||
belongs_to :author, foreign_key: :author_statistic_profile_id, class_name: 'StatisticProfile'
|
||||
belongs_to :licence, foreign_key: :licence_id
|
||||
|
||||
has_many :project_steps, dependent: :destroy
|
||||
@ -39,22 +44,22 @@ class Project < ActiveRecord::Base
|
||||
|
||||
after_save :after_save_and_publish
|
||||
|
||||
aasm :column => 'state' do
|
||||
aasm column: 'state' do
|
||||
state :draft, initial: true
|
||||
state :published
|
||||
|
||||
event :publish, :after => :notify_admin_when_project_published do
|
||||
transitions from: :draft, :to => :published
|
||||
event :publish, after: :notify_admin_when_project_published do
|
||||
transitions from: :draft, to: :published
|
||||
end
|
||||
end
|
||||
|
||||
#scopes
|
||||
# scopes
|
||||
scope :published, -> { where("state = 'published'") }
|
||||
|
||||
## elastic
|
||||
# callbacks
|
||||
after_save { ProjectIndexerWorker.perform_async(:index, self.id) }
|
||||
after_destroy { ProjectIndexerWorker.perform_async(:delete, self.id) }
|
||||
after_save { ProjectIndexerWorker.perform_async(:index, id) }
|
||||
after_destroy { ProjectIndexerWorker.perform_async(:delete, id) }
|
||||
|
||||
# mapping
|
||||
settings index: { number_of_replicas: 0 } do
|
||||
@ -64,31 +69,19 @@ class Project < ActiveRecord::Base
|
||||
indexes 'name', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
indexes 'description', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
indexes 'project_steps' do
|
||||
indexes 'title', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
indexes 'description', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
indexes 'title', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
indexes 'description', analyzer: Rails.application.secrets.elasticsearch_language_analyzer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def as_indexed_json
|
||||
Jbuilder.new do |json|
|
||||
json.id id
|
||||
json.state state
|
||||
json.author_id author_id
|
||||
json.user_ids user_ids
|
||||
json.machine_ids machine_ids
|
||||
json.theme_ids theme_ids
|
||||
json.component_ids component_ids
|
||||
json.tags tags
|
||||
json.name name
|
||||
json.description description
|
||||
json.project_steps project_steps do |project_step|
|
||||
json.title project_step.title
|
||||
json.description project_step.description
|
||||
end
|
||||
json.created_at created_at
|
||||
json.updated_at updated_at
|
||||
end.target!
|
||||
ApplicationController.new.view_context.render(
|
||||
partial: 'api/projects/indexed',
|
||||
locals: { project: self },
|
||||
formats: [:json],
|
||||
handlers: [:jbuilder]
|
||||
)
|
||||
end
|
||||
|
||||
def self.search(params, current_user)
|
||||
@ -101,43 +94,45 @@ class Project < ActiveRecord::Base
|
||||
bool: {
|
||||
must: [],
|
||||
should: [],
|
||||
filter: [],
|
||||
filter: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if params['q'].blank? # we sort by created_at if there isn't a query
|
||||
# we sort by created_at if there isn't a query
|
||||
if params['q'].blank?
|
||||
search[:sort] = { created_at: { order: :desc } }
|
||||
else # otherwise we search for the word (q) in various fields
|
||||
else
|
||||
# otherwise we search for the word (q) in various fields
|
||||
search[:query][:bool][:must] << {
|
||||
multi_match: {
|
||||
query: params['q'],
|
||||
type: 'most_fields',
|
||||
fields: %w(tags^4 name^5 description^3 project_steps.title^2 project_steps.description)
|
||||
fields: %w[tags^4 name^5 description^3 project_steps.title^2 project_steps.description]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
params.each do |name, value| # we filter by themes, components, machines
|
||||
# we filter by themes, components, machines
|
||||
params.each do |name, value|
|
||||
if name =~ /(.+_id$)/
|
||||
search[:query][:bool][:filter] << { term: { "#{name}s" => value } } if value
|
||||
end
|
||||
end
|
||||
|
||||
if current_user and params.key?('from') # if use select filter 'my project' or 'my collaborations'
|
||||
if params['from'] == 'mine'
|
||||
search[:query][:bool][:filter] << { term: { author_id: current_user.id } }
|
||||
end
|
||||
if params['from'] == 'collaboration'
|
||||
search[:query][:bool][:filter] << { term: { user_ids: current_user.id } }
|
||||
end
|
||||
# if use select filter 'my project' or 'my collaborations'
|
||||
if current_user && params.key?('from')
|
||||
search[:query][:bool][:filter] << { term: { author_id: current_user.id } } if params['from'] == 'mine'
|
||||
search[:query][:bool][:filter] << { term: { user_ids: current_user.id } } if params['from'] == 'collaboration'
|
||||
end
|
||||
|
||||
if current_user # if user is connected, also display his draft projects
|
||||
# if user is connected, also display his draft projects
|
||||
if current_user
|
||||
search[:query][:bool][:should] << { term: { state: 'published' } }
|
||||
search[:query][:bool][:should] << { term: { author_id: current_user.id } }
|
||||
search[:query][:bool][:should] << { term: { user_ids: current_user.id } }
|
||||
else # otherwise display only published projects
|
||||
else
|
||||
# otherwise display only published projects
|
||||
search[:query][:bool][:must] << { term: { state: 'published' } }
|
||||
end
|
||||
|
||||
@ -145,6 +140,7 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notify_admin_when_project_published
|
||||
NotificationCenter.call type: 'notify_admin_when_project_published',
|
||||
receiver: User.admins,
|
||||
@ -152,9 +148,9 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def after_save_and_publish
|
||||
if state_changed? and published?
|
||||
update_columns(published_at: Time.now)
|
||||
notify_admin_when_project_published
|
||||
end
|
||||
return unless state_changed? && published?
|
||||
|
||||
update_columns(published_at: Time.now)
|
||||
notify_admin_when_project_published
|
||||
end
|
||||
end
|
||||
|
@ -21,6 +21,9 @@ class StatisticProfile < ActiveRecord::Base
|
||||
has_many :statistic_profile_trainings, dependent: :destroy
|
||||
has_many :trainings, through: :statistic_profile_trainings
|
||||
|
||||
# Projects that the current user is the author
|
||||
has_many :my_projects, foreign_key: :author_statistic_profile_id, class_name: 'Project', dependent: :destroy
|
||||
|
||||
def str_gender
|
||||
gender ? 'male' : 'female'
|
||||
end
|
||||
|
@ -27,7 +27,6 @@ class User < ActiveRecord::Base
|
||||
has_one :statistic_profile, dependent: :nullify
|
||||
accepts_nested_attributes_for :statistic_profile
|
||||
|
||||
has_many :my_projects, foreign_key: :author_id, class_name: 'Project', dependent: :destroy
|
||||
has_many :project_users, dependent: :destroy
|
||||
has_many :projects, through: :project_users
|
||||
|
||||
@ -66,6 +65,7 @@ class User < ActiveRecord::Base
|
||||
delegate :subscriptions, to: :statistic_profile
|
||||
delegate :reservations, to: :statistic_profile
|
||||
delegate :trainings, to: :statistic_profile
|
||||
delegate :my_projects, to: :statistic_profile
|
||||
delegate :wallet, to: :invoicing_profile
|
||||
delegate :wallet_transactions, to: :invoicing_profile
|
||||
delegate :invoices, to: :invoicing_profile
|
||||
|
@ -2,23 +2,24 @@ class ProjectPolicy < ApplicationPolicy
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
if user
|
||||
statistic_profile = StatisticProfile.find_by(user_id: user.id)
|
||||
scope.includes(:project_image, :machines, :users)
|
||||
.where("state = 'published' OR (state = 'draft' AND (author_id = ? OR users.id = ?))", user.id, user.id)
|
||||
.references(:users)
|
||||
.order(created_at: :desc)
|
||||
.where("state = 'published' OR (state = 'draft' AND (author_statistic_profile_id = ? OR users.id = ?))", statistic_profile.id, user.id)
|
||||
.references(:users)
|
||||
.order(created_at: :desc)
|
||||
else
|
||||
scope.includes(:project_image, :machines, :users)
|
||||
.where("state = 'published'")
|
||||
.order(created_at: :desc)
|
||||
.where("state = 'published'")
|
||||
.order(created_at: :desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update?
|
||||
user.admin? or record.author == user or record.users.include?(user)
|
||||
user.admin? or record.author.user_id == user.id or record.users.include?(user)
|
||||
end
|
||||
|
||||
def destroy?
|
||||
user.admin? or record.author == user
|
||||
user.admin? or record.author.user_id == user
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ class Availabilities::StatusService
|
||||
|
||||
# check that the provided machine slot is reserved or not and modify it accordingly
|
||||
def machine_reserved_status(slot, reservations, user)
|
||||
statistic_profile_id = user.statistic_profile.id
|
||||
statistic_profile_id = user&.statistic_profile&.id
|
||||
reservations.each do |r|
|
||||
r.slots.each do |s|
|
||||
next unless slot.machine.id == r.reservable_id
|
||||
@ -34,7 +34,7 @@ class Availabilities::StatusService
|
||||
|
||||
# check that the provided space slot is reserved or not and modify it accordingly
|
||||
def space_reserved_status(slot, reservations, user)
|
||||
statistic_profile_id = user.statistic_profile.id
|
||||
statistic_profile_id = user&.statistic_profile&.id
|
||||
reservations.each do |r|
|
||||
r.slots.each do |s|
|
||||
next unless slot.space.id == r.reservable_id
|
||||
@ -57,7 +57,7 @@ class Availabilities::StatusService
|
||||
|
||||
# check that the provided availability (training or event) is reserved or not and modify it accordingly
|
||||
def training_event_reserved_status(availability, reservations, user)
|
||||
statistic_profile_id = user.statistic_profile.id
|
||||
statistic_profile_id = user&.statistic_profile&.id
|
||||
reservations.each do |r|
|
||||
r.slots.each do |s|
|
||||
next unless (
|
||||
|
@ -10,7 +10,7 @@ class Reservations::Reserve
|
||||
end
|
||||
|
||||
def pay_and_save(reservation, payment_method, coupon)
|
||||
reservation.statistic_profile_id = User.find(user_id).statistic_profile.id
|
||||
reservation.statistic_profile_id = StatisticProfile.find_by(user_id: user_id).id
|
||||
if payment_method == :local
|
||||
reservation.save_with_local_payment(operator_id, coupon)
|
||||
elsif payment_method == :stripe
|
||||
|
@ -305,7 +305,7 @@ class StatisticService
|
||||
def projects_list(options = default_options)
|
||||
result = []
|
||||
Project.where('projects.published_at >= :start_date AND projects.published_at <= :end_date', options)
|
||||
.eager_load(:licence, :themes, :components, :machines, :project_users, author: %i[profile group])
|
||||
.eager_load(:licence, :themes, :components, :machines, :project_users, author: %i[group])
|
||||
.each do |p|
|
||||
result.push OpenStruct.new({
|
||||
date: options[:start_date].to_date
|
||||
|
@ -12,7 +12,7 @@ class Subscriptions::Subscribe
|
||||
def pay_and_save(subscription, payment_method, coupon, invoice)
|
||||
return false if user_id.nil?
|
||||
|
||||
subscription.statistic_profile_id = User.find(user_id).statistic_profile.id
|
||||
subscription.statistic_profile_id = StatisticProfile.find_by(user_id: user_id).id
|
||||
if payment_method == :local
|
||||
subscription.save_with_local_payment(operator_id, invoice, coupon)
|
||||
elsif payment_method == :stripe
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
requested_current = (current_user and current_user.id == @member.id)
|
||||
|
||||
json.partial! 'api/members/member', member: @member
|
||||
@ -19,7 +21,8 @@ end
|
||||
|
||||
json.all_projects @member.all_projects do |project|
|
||||
if requested_current || project.state == 'published'
|
||||
json.extract! project, :id, :name, :description, :author_id, :licence_id, :slug, :state
|
||||
json.extract! project, :id, :name, :description, :licence_id, :slug, :state
|
||||
json.author_id project.author.user_id
|
||||
json.url project_url(project, format: :json)
|
||||
json.project_image project.project_image.attachment.large.url if project.project_image
|
||||
json.machine_ids project.machine_ids
|
||||
@ -27,7 +30,6 @@ json.all_projects @member.all_projects do |project|
|
||||
json.id m.id
|
||||
json.name m.name
|
||||
end
|
||||
json.author_id project.author_id
|
||||
json.user_ids project.user_ids
|
||||
json.component_ids project.component_ids
|
||||
json.components project.components do |c|
|
||||
@ -69,7 +71,7 @@ json.invoices @member.invoices.order('reference DESC') do |i|
|
||||
json.reference i.reference
|
||||
json.type i.invoiced_type
|
||||
json.invoiced_id i.invoiced_id
|
||||
json.total (i.total / 100.00)
|
||||
json.total i.total / 100.00
|
||||
json.is_avoir i.is_a?(Avoir)
|
||||
json.date i.is_a?(Avoir) ? i.avoir_date : i.created_at
|
||||
end
|
||||
|
18
app/views/api/projects/_indexed.json.jbuilder
Normal file
18
app/views/api/projects/_indexed.json.jbuilder
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.id project.id
|
||||
json.state project.state
|
||||
json.author_id project.author.user_id
|
||||
json.user_ids project.user_ids
|
||||
json.machine_ids project.machine_ids
|
||||
json.theme_ids project.theme_ids
|
||||
json.component_ids project.component_ids
|
||||
json.tags project.tags
|
||||
json.name project.name
|
||||
json.description project.description
|
||||
json.project_steps project.project_steps do |project_step|
|
||||
json.title project_step.title
|
||||
json.description project_step.description
|
||||
end
|
||||
json.created_at project.created_at
|
||||
json.updated_at project.updated_at
|
@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.projects @projects do |project|
|
||||
json.extract! project, :id, :name, :description, :author_id, :licence_id, :slug, :state
|
||||
json.extract! project, :id, :name, :description, :licence_id, :slug, :state
|
||||
json.author_id project.author.user_id
|
||||
json.url project_url(project, format: :json)
|
||||
json.project_image project.project_image.attachment.medium.url if project.project_image
|
||||
json.author_id project.author_id
|
||||
json.user_ids project.user_ids
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@projects) do |project|
|
||||
json.extract! project, :id, :name, :description, :slug
|
||||
json.url project_url(project, format: :json)
|
||||
|
@ -1,17 +1,22 @@
|
||||
json.extract! @project, :id, :name, :description, :tags, :created_at, :updated_at, :author_id, :licence_id, :slug
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! @project, :id, :name, :description, :tags, :created_at, :updated_at, :licence_id, :slug
|
||||
json.author_id @project.author.user_id
|
||||
json.project_image @project.project_image.attachment.large.url if @project.project_image
|
||||
json.project_full_image @project.project_image.attachment.url if @project.project_image
|
||||
json.author do
|
||||
json.id @project.author_id
|
||||
json.first_name @project.author.profile.first_name
|
||||
json.last_name @project.author.profile.last_name
|
||||
json.full_name @project.author.profile.full_name
|
||||
json.user_avatar do
|
||||
json.id @project.author.profile.user_avatar.id
|
||||
json.attachment_url @project.author.profile.user_avatar.attachment_url
|
||||
end if @project.author.profile.user_avatar
|
||||
json.username @project.author.username
|
||||
json.slug @project.author.slug
|
||||
json.id @project.author.user_id
|
||||
json.first_name @project.author&.user&.profile&.first_name
|
||||
json.last_name @project.author&.user&.profile&.last_name
|
||||
json.full_name @project.author&.user&.profile&.full_name
|
||||
if @project.author&.user&.profile&.user_avatar
|
||||
json.user_avatar do
|
||||
json.id @project.author&.user&.profile&.user_avatar&.id
|
||||
json.attachment_url @project.author&.user&.profile&.user_avatar&.attachment_url
|
||||
end
|
||||
end
|
||||
json.username @project.author&.user&.username
|
||||
json.slug @project.author&.user&.slug
|
||||
end
|
||||
json.project_caos_attributes @project.project_caos do |f|
|
||||
json.id f.id
|
||||
@ -39,10 +44,12 @@ json.project_users @project.project_users do |pu|
|
||||
json.first_name pu.user.profile.first_name
|
||||
json.last_name pu.user.profile.last_name
|
||||
json.full_name pu.user.profile.full_name
|
||||
json.user_avatar do
|
||||
json.id pu.user.profile.user_avatar.id
|
||||
json.attachment_url pu.user.profile.user_avatar.attachment_url
|
||||
end if pu.user.profile.user_avatar
|
||||
if pu.user.profile.user_avatar
|
||||
json.user_avatar do
|
||||
json.id pu.user.profile.user_avatar.id
|
||||
json.attachment_url pu.user.profile.user_avatar.attachment_url
|
||||
end
|
||||
end
|
||||
json.username pu.user.username
|
||||
json.slug pu.user.slug
|
||||
json.is_valid pu.is_valid
|
||||
@ -60,9 +67,8 @@ json.project_steps_attributes @project.project_steps.order('project_steps.step_n
|
||||
json.step_nb s.step_nb
|
||||
end
|
||||
json.state @project.state
|
||||
json.licence do
|
||||
json.name @project.licence.name
|
||||
end if @project.licence.present?
|
||||
#json.project_steps_attributes @project.project_steps do |s|
|
||||
#json.set! s.id, {id: s.id, description: s.description}
|
||||
#end
|
||||
if @project.licence.present?
|
||||
json.licence do
|
||||
json.name @project.licence.name
|
||||
end
|
||||
end
|
||||
|
@ -9,20 +9,20 @@ class AvailabilityIndexerWorker
|
||||
logger.debug [operation, "ID: #{record_id}"]
|
||||
|
||||
case operation.to_s
|
||||
when /index/
|
||||
begin
|
||||
record = Availability.find(record_id)
|
||||
Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
STDERR.puts "Availability id(#{record_id}) will not be indexed in ElasticSearch as it does not exists anymore in database"
|
||||
end
|
||||
when /delete/
|
||||
begin
|
||||
Client.delete index: Availability.index_name, type: Availability.document_type, id: record_id
|
||||
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
||||
STDERR.puts "Availability id(#{record_id}) will not be deleted form ElasticSearch as it has not been already indexed"
|
||||
end
|
||||
else raise ArgumentError, "Unknown operation '#{operation}'"
|
||||
when /index/
|
||||
begin
|
||||
record = Availability.find(record_id)
|
||||
Client.index index: Availability.index_name, type: Availability.document_type, id: record.id, body: record.as_indexed_json
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
STDERR.puts "Availability id(#{record_id}) will not be indexed in ElasticSearch as it does not exists anymore in database"
|
||||
end
|
||||
when /delete/
|
||||
begin
|
||||
Client.delete index: Availability.index_name, type: Availability.document_type, id: record_id
|
||||
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
||||
STDERR.puts "Availability id(#{record_id}) will not be deleted form ElasticSearch as it has not been already indexed"
|
||||
end
|
||||
else raise ArgumentError, "Unknown operation '#{operation}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
fr:
|
||||
devise:
|
||||
confirmations:
|
||||
confirmed: "Votre compte a été confirmé avec succès. Vous êtes désormais connecté(e)."
|
||||
confirmed: "Votre compte a été confirmé avec succès."
|
||||
send_instructions: "Vous allez recevoir sous quelques minutes un e-mail comportant des instructions pour confirmer votre compte."
|
||||
send_paranoid_instructions: "Si votre e-mail existe sur notre base de données, vous recevrez sous quelques minutes un message avec des instructions pour confirmer votre compte."
|
||||
failure:
|
||||
|
@ -10,5 +10,8 @@ class CreateStatisticProfile < ActiveRecord::Migration
|
||||
|
||||
add_reference :reservations, :statistic_profile, index: true, foreign_key: true
|
||||
add_reference :subscriptions, :statistic_profile, index: true, foreign_key: true
|
||||
|
||||
add_column :projects, :author_statistic_profile_id, :integer, index: true
|
||||
add_foreign_key :projects, :statistic_profiles, column: :author_statistic_profile_id
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,19 @@
|
||||
class MigrateProjetToStatisticProfile < ActiveRecord::Migration
|
||||
def up
|
||||
Project.all.each do |p|
|
||||
author = User.find(p.author_id)
|
||||
p.update_column(
|
||||
'author_statistic_profile_id', author.statistic_profile.id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
Project.all.each do |p|
|
||||
statistic_profile = User.find(p.author_statistic_profile_id)
|
||||
p.update_column(
|
||||
'author_id', statistic_profile.user_id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
@ -4,5 +4,6 @@ class RemoveStatisticColumns < ActiveRecord::Migration
|
||||
remove_column :profiles, :birthday, :date
|
||||
remove_column :reservations, :user_id
|
||||
remove_column :subscriptions, :user_id
|
||||
remove_column :projects, :author_id
|
||||
end
|
||||
end
|
||||
|
@ -5,16 +5,28 @@ class MigrateUserTrainingsToStatisticProfileTrainings < ActiveRecord::Migration
|
||||
user_trainings.each do |ut|
|
||||
user = User.find(ut['user_id'])
|
||||
# here we use raw sql to prevent the notify_user callback the email the whole DB
|
||||
execute("INSERT INTO statistic_profile_trainings (statistic_profile_id, training_id, created_at, updated_at)
|
||||
VALUES (#{user.statistic_profile.id}, #{ut['training_id']}, '#{ut['created_at'].utc}', '#{DateTime.now.utc}')")
|
||||
spt_id = insert("INSERT INTO statistic_profile_trainings (statistic_profile_id, training_id, created_at, updated_at)
|
||||
VALUES (#{user.statistic_profile.id}, #{ut['training_id']}, '#{ut['created_at']}', '#{DateTime.now.utc}')")
|
||||
|
||||
# update notifications
|
||||
execute("UPDATE notifications SET
|
||||
attached_object_type = 'StatisticProfileTraining',
|
||||
attached_object_id = #{spt_id},
|
||||
updated_at = '#{DateTime.now.utc}'
|
||||
WHERE attached_object_id = #{ut['id']} AND attached_object_type = 'UserTraining'")
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
StatisticProfileTraining.all.each do |spt|
|
||||
statistic_profile = StatisticProfile.find(spt.statistic_profile_id)
|
||||
execute("INSERT INTO user_trainings (user_id, training_id, created_at, updated_at)
|
||||
VALUES (#{statistic_profile.user_id}, #{spt.training_id}, '#{spt.created_at.utc}', '#{DateTime.now.utc}')")
|
||||
ut_id = execute("INSERT INTO user_trainings (user_id, training_id, created_at, updated_at)
|
||||
VALUES (#{statistic_profile.user_id}, #{spt.training_id}, '#{spt.created_at.utc}', '#{DateTime.now.utc}')")
|
||||
execute("UPDATE notifications SET
|
||||
attached_object_type = 'UserTraining',
|
||||
attached_object_id = #{ut_id},
|
||||
updated_at = '#{DateTime.now.utc}'
|
||||
WHERE attached_object_id = #{spt.id} AND attached_object_type = 'StatisticProfileTraining'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -496,16 +496,16 @@ ActiveRecord::Schema.define(version: 20190606074801) do
|
||||
add_index "project_users", ["user_id"], name: "index_project_users_on_user_id", using: :btree
|
||||
|
||||
create_table "projects", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "name", limit: 255
|
||||
t.text "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "author_id"
|
||||
t.text "tags"
|
||||
t.integer "licence_id"
|
||||
t.string "state", limit: 255
|
||||
t.string "slug", limit: 255
|
||||
t.string "state", limit: 255
|
||||
t.string "slug", limit: 255
|
||||
t.datetime "published_at"
|
||||
t.integer "author_statistic_profile_id"
|
||||
end
|
||||
|
||||
add_index "projects", ["slug"], name: "index_projects_on_slug", using: :btree
|
||||
@ -914,6 +914,7 @@ ActiveRecord::Schema.define(version: 20190606074801) do
|
||||
add_foreign_key "organizations", "invoicing_profiles"
|
||||
add_foreign_key "prices", "groups"
|
||||
add_foreign_key "prices", "plans"
|
||||
add_foreign_key "projects", "statistic_profiles", column: "author_statistic_profile_id"
|
||||
add_foreign_key "projects_spaces", "projects"
|
||||
add_foreign_key "projects_spaces", "spaces"
|
||||
add_foreign_key "reservations", "statistic_profiles"
|
||||
|
2
test/fixtures/projects.yml
vendored
2
test/fixtures/projects.yml
vendored
@ -6,7 +6,7 @@ project_1:
|
||||
pommes de terre ou d'outres légumes afin de confectionner de la purée.<br></p>"
|
||||
created_at: 2016-04-04 15:39:08.224918000 Z
|
||||
updated_at: 2016-04-04 15:39:08.224918000 Z
|
||||
author_id: 5
|
||||
author_statistic_profile_id: 5
|
||||
tags: cuisine
|
||||
licence_id: 1
|
||||
state: published
|
||||
|
Loading…
x
Reference in New Issue
Block a user