-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added support for rooms * changed rooms to room adverts * remove one room advert policy rule * minor change * making public room adverts visible to public website * more small fixes
- Loading branch information
1 parent
27772be
commit 3e13408
Showing
17 changed files
with
433 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class V1::RoomAdvertsController < V1::ApplicationController | ||
before_action :doorkeeper_authorize!, except: %i[index show] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class RoomAdvert < ApplicationRecord | ||
mount_base64_uploader :cover_photo, CoverPhotoUploader | ||
|
||
belongs_to :author, class_name: 'User' | ||
|
||
validates :house_name, presence: true | ||
validates :contact, presence: true | ||
validates :description, presence: true | ||
validates :publicly_visible, inclusion: [true, false] | ||
|
||
scope :publicly_visible, (-> { where(publicly_visible: true) }) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class RoomAdvertPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
if user_can_read? | ||
scope | ||
else | ||
scope.publicly_visible | ||
end | ||
end | ||
end | ||
|
||
def index? | ||
true | ||
end | ||
|
||
def show? | ||
super || scope.exists?(id: record.id) | ||
end | ||
|
||
def update? | ||
user_is_owner? || super | ||
end | ||
|
||
def destroy? | ||
user_is_owner? || super | ||
end | ||
|
||
private | ||
|
||
def user_is_owner? | ||
record.author == user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class V1::RoomAdvertResource < V1::ApplicationResource | ||
attributes :house_name, :contact, :location, :available_from, | ||
:description, :description_camofied, :author_name, | ||
:cover_photo_url, :cover_photo, :publicly_visible | ||
|
||
def cover_photo_url | ||
@model.cover_photo.url | ||
end | ||
|
||
def description_camofied | ||
camofy(@model['description']) | ||
end | ||
|
||
def author_name | ||
@model.author.full_name | ||
end | ||
|
||
has_one :author, always_include_linkage_data: true | ||
|
||
def fetchable_fields | ||
super - [:cover_photo] | ||
end | ||
|
||
def self.creatable_fields(_context) | ||
%i[house_name contact location available_from description cover_photo publicly_visible] | ||
end | ||
|
||
before_create do | ||
@model.author_id = current_user.id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateRoomAdverts < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :room_adverts do |t| | ||
t.string :house_name, null: false | ||
t.string :contact, null: false | ||
t.string :location | ||
t.string :available_from | ||
t.string :description, null: false | ||
t.string :cover_photo | ||
t.boolean :publicly_visible | ||
t.integer :author_id | ||
t.datetime :deleted_at | ||
|
||
t.timestamps | ||
end | ||
|
||
Permission.create(name: 'room_advert.create') | ||
Permission.create(name: 'room_advert.read') | ||
Permission.create(name: 'room_advert.update') | ||
Permission.create(name: 'room_advert.destroy') | ||
end | ||
end |
Oops, something went wrong.