Skip to content

Commit

Permalink
Merge pull request #310 from diegosteiner/develop
Browse files Browse the repository at this point in the history
24.5.1
  • Loading branch information
diegosteiner committed May 15, 2024
2 parents 488b90e + 1f42c18 commit 175ebdb
Show file tree
Hide file tree
Showing 37 changed files with 233 additions and 240 deletions.
38 changes: 19 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.924.0)
aws-sdk-core (3.194.1)
aws-partitions (1.928.0)
aws-sdk-core (3.196.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.80.0)
aws-sdk-kms (1.81.0)
aws-sdk-core (~> 3, >= 3.193.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.149.0)
aws-sdk-s3 (1.150.0)
aws-sdk-core (~> 3, >= 3.194.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
Expand All @@ -108,7 +108,7 @@ GEM
statsd-ruby (~> 1.1)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.7)
bigdecimal (3.1.8)
blueprinter (1.0.2)
bootsnap (1.18.3)
msgpack (~> 1.2)
Expand Down Expand Up @@ -167,9 +167,9 @@ GEM
discard (1.3.0)
activerecord (>= 4.2, < 8)
docile (1.4.0)
dotenv (3.1.1)
dotenv-rails (3.1.1)
dotenv (= 3.1.1)
dotenv (3.1.2)
dotenv-rails (3.1.2)
dotenv (= 3.1.2)
railties (>= 6.1)
drb (2.2.1)
dry-cli (1.0.0)
Expand Down Expand Up @@ -234,7 +234,7 @@ GEM
globalid (1.2.1)
activesupport (>= 6.1)
highline (3.0.1)
i18n (1.14.4)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
i18n-tasks (0.9.37)
activesupport (>= 4.0.2)
Expand Down Expand Up @@ -294,7 +294,7 @@ GEM
mutex_m (0.2.0)
net-http (0.4.1)
uri
net-imap (0.4.10)
net-imap (0.4.11)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -303,8 +303,8 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.4-x86_64-linux)
nio4r (2.7.3)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.24.0)
Expand Down Expand Up @@ -341,7 +341,7 @@ GEM
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.7.3)
rack (3.0.10)
rack (3.0.11)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-proxy (0.7.7)
Expand Down Expand Up @@ -404,8 +404,8 @@ GEM
redis-client (>= 0.22.0)
redis-client (0.22.1)
connection_pool
regexp_parser (2.9.0)
reline (0.5.5)
regexp_parser (2.9.1)
reline (0.5.7)
io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
Expand All @@ -422,7 +422,7 @@ GEM
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.2)
Expand All @@ -434,7 +434,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.63.4)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -502,7 +502,7 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
sorbet-runtime (0.5.11368)
sorbet-runtime (0.5.11375)
squasher (0.8.0)
statesman (12.1.0)
statsd-ruby (1.5.0)
Expand Down Expand Up @@ -541,7 +541,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.13)
zeitwerk (2.6.14)

PLATFORMS
x86_64-linux-musl
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage/occupiables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def update
end

def destroy
@occupiable.destroy
@occupiable.discarded? ? @occupiable.destroy : @occupiable.discard!
respond_with :manage, @occupiable, location: manage_occupiables_path
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/manage/organisation_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def create
else
email = params.dig(:organisation_user, :email)
onboarding = OnboardingService.new(current_organisation)
@organisation_user = onboarding.add_or_invite_user!(email:, role: organisation_user_params[:role],
invited_by: current_user)
@organisation_user = onboarding.add_or_invite_user(email:, role: organisation_user_params[:role],
invited_by: current_user)
end
respond_with :manage, @organisation_user, location: manage_organisation_users_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/public/homes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class HomesController < BaseController
load_and_authorize_resource :home

def index
@homes = @homes.where(organisation: current_organisation).active
@homes = @homes.where(organisation: current_organisation).kept
respond_with :public, @homes
end

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/occupiables/OccupiableSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function OccupiableSelect({
const organisation = useContext(OrganisationContext);
const home = organisation?.homes?.find((home) => home.id === homeId);
const occupiables = home?.occupiables
?.filter((occupiable) => occupiable.occupiable && occupiable.active)
?.filter((occupiable) => occupiable.occupiable && !occupiable.discarded_at)
?.sort(ordinalOrder);
const hideHomeSelect = organisation?.homes?.length === 1;
const setHomeId = (homeId: number) => {
Expand Down
20 changes: 7 additions & 13 deletions app/javascript/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,24 @@ export type BookingCategory = {
title_i18n: TranslatedString;
};

export type Home = {
id: number;
active: boolean;
description: string;
description_i18n: TranslatedString;
home_id: number;
name: string;
name_i18n: TranslatedString;
occupiable: boolean;
occupiables: Occupiable[];
};

export type Occupiable = {
id: number;
organisation_id: number;
ref: string | null;
// janitor: null;
active: boolean;
discarded_at: string;
created_at: Date;
updated_at: Date;
occupiable: boolean;
home_id: number;
// settings: Settings;
ordinal: number | undefined;
name_i18n: TranslatedString;
name: string;
description_i18n: TranslatedString;
description: string;
};

export type Home = Occupiable & {
occupiables: Occupiable[];
};
8 changes: 4 additions & 4 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ class Manage < Base

class Public < Base
role nil do |_user, organisation|
can :read, Home, { organisation:, active: true }
can :read, Occupiable, { organisation:, active: true }
can :read, Home, { organisation:, discarded_at: nil }
can :read, Occupiable, { organisation:, discarded_at: nil }

can %i[read embed calendar at], Occupancy, occupiable: { active: true, organisation: }
can %i[read embed calendar at], Occupancy, occupiable: { discarded_at: nil, organisation: }

can %i[create read update], AgentBooking, { organisation: }
can %i[create read update], Booking, { organisation:, concluded: false }
end

role :readonly do |_user, organisation|
can :read, Home, { organisation: }
can :read, Occupiable, { organisation:, active: true }
can :read, Occupiable, { organisation: }
can :read, Organisation, id: organisation.id

can %i[read embed calendar at], Occupancy, occupiable: { organisation: }
Expand Down
3 changes: 2 additions & 1 deletion app/models/home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Table name: occupiables
#
# id :bigint not null, primary key
# active :boolean default(FALSE)
# description_i18n :jsonb
# discarded_at :datetime
# janitor :text
# name_i18n :jsonb
# occupiable :boolean default(FALSE)
Expand All @@ -21,6 +21,7 @@
#
# Indexes
#
# index_occupiables_on_discarded_at (discarded_at)
# index_occupiables_on_home_id (home_id)
# index_occupiables_on_organisation_id (organisation_id)
# index_occupiables_on_ref_and_organisation_id (ref,organisation_id) UNIQUE
Expand Down
3 changes: 1 addition & 2 deletions app/models/invoice_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class Filter < ApplicationFilter
filter :homes do |invoice_parts|
relevant_homes = Array.wrap(homes).compact_blank
if relevant_homes.present?
invoice_parts.joins(invoice: :booking)
.where(invoice: { bookings: { home_id: relevant_homes } })
invoice_parts.joins(invoice: :booking).where(invoices: { bookings: { home_id: relevant_homes } })
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/models/occupiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Table name: occupiables
#
# id :bigint not null, primary key
# active :boolean default(FALSE)
# description_i18n :jsonb
# discarded_at :datetime
# janitor :text
# name_i18n :jsonb
# occupiable :boolean default(FALSE)
Expand All @@ -21,6 +21,7 @@
#
# Indexes
#
# index_occupiables_on_discarded_at (discarded_at)
# index_occupiables_on_home_id (home_id)
# index_occupiables_on_organisation_id (organisation_id)
# index_occupiables_on_ref_and_organisation_id (ref,organisation_id) UNIQUE
Expand All @@ -32,6 +33,7 @@

class Occupiable < ApplicationRecord
include RankedModel
include Discard::Model
extend Mobility

has_many :occupancies, -> { ordered }, inverse_of: :occupiable, dependent: :restrict_with_error
Expand All @@ -46,7 +48,6 @@ class Occupiable < ApplicationRecord
normalizes :ref, with: -> { _1.presence&.strip }

scope :occupiable, -> { where(occupiable: true) }
scope :active, -> { where(active: true) }
scope :ordered, -> { rank(:ordinal) }

validates :name, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/params/manage/occupiable_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Manage
class OccupiableParams < ApplicationParams
def self.permitted_keys
%i[name description active occupiable type ref home_id ordinal_position] +
%i[name description occupiable type ref home_id ordinal_position] +
I18n.available_locales.map { |locale| ["name_#{locale}", "description_#{locale}"] }.flatten +
[{ settings: %i[booking_margin] }]
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/manage/home_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class HomeSerializer < Public::HomeSerializer
fields :janitor, :description

view :export do
fields :active, :occupiable, :home_id
fields :discarded_at, :occupiable, :home_id

include_view :default
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/public/home_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Public
class HomeSerializer < OccupiableSerializer
association :occupiables, blueprint: Public::OccupiableSerializer do |home|
home.occupiables.active
home.occupiables.kept
end
end
end
2 changes: 1 addition & 1 deletion app/serializers/public/occupiable_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module Public
class OccupiableSerializer < ApplicationSerializer
identifier :id
fields :name, :description, :active, :occupiable, :home_id, :name_i18n, :description_i18n, :ordinal
fields :name, :description, :discarded_at, :occupiable, :home_id, :name_i18n, :description_i18n, :ordinal
end
end
2 changes: 1 addition & 1 deletion app/serializers/public/organisation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OrganisationSerializer < ApplicationSerializer

association :booking_categories, blueprint: Public::BookingCategorySerializer
association :homes, blueprint: Public::HomeSerializer do |organisation|
organisation.homes.active
organisation.homes.kept
end

fields :name, :address, :email, :currency, :country_code
Expand Down
2 changes: 1 addition & 1 deletion app/services/import/hash/home_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Hash
class HomeImporter < Base
attr_reader :organisation

use_attributes(*%w[name description active ref occupiable home_id])
use_attributes(*%w[name description discarded_at ref occupiable home_id])

def initialize(organisation, **options)
super(**options)
Expand Down
10 changes: 7 additions & 3 deletions app/services/onboarding_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ def self.clone_organisation(origin)
new(origin.dup)
end

def add_or_invite_user!(email: organisation.email, role: :manager, invited_by: nil, password: nil)
def add_or_invite_user!(...)
add_or_invite_user(...).save!
end

def add_or_invite_user(email: organisation.email, role: :manager, invited_by: nil, password: nil)
user = User.find_or_initialize_by(email:)

if user.new_record?
user.update!(password: password || SecureRandom.base64(32))
user.invite!(invited_by) if password.blank?
end

user.organisation_users.create!(organisation:, role:).tap do
user.update!(default_organisation: organisation) if user.default_organisation.blank?
user.organisation_users.create(organisation:, role:).tap do
user.update(default_organisation: organisation) if user.default_organisation.blank?
end
end

Expand Down
Loading

0 comments on commit 175ebdb

Please sign in to comment.