Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.3.8'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 7.1.0'
gem 'rails', '~> 7.2.0'
# Use Puma as the app server
gem 'puma', '~> 6.4'
# Use SCSS for stylesheets
Expand All @@ -23,9 +23,6 @@ gem 'redis', '~> 5.0'
gem 'stimulus-rails', '~> 1.3'
gem 'turbo-rails', '~> 1.5'

gem 'delayed_job', '~> 4.1'
gem 'delayed_job_active_record', '~> 4.1'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

Expand Down
137 changes: 62 additions & 75 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,83 +1,77 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.5.1)
actionpack (= 7.1.5.1)
activesupport (= 7.1.5.1)
actioncable (7.2.2.1)
actionpack (= 7.2.2.1)
activesupport (= 7.2.2.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.5.1)
actionpack (= 7.1.5.1)
activejob (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.5.1)
actionpack (= 7.1.5.1)
actionview (= 7.1.5.1)
activejob (= 7.1.5.1)
activesupport (= 7.1.5.1)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
actionmailbox (7.2.2.1)
actionpack (= 7.2.2.1)
activejob (= 7.2.2.1)
activerecord (= 7.2.2.1)
activestorage (= 7.2.2.1)
activesupport (= 7.2.2.1)
mail (>= 2.8.0)
actionmailer (7.2.2.1)
actionpack (= 7.2.2.1)
actionview (= 7.2.2.1)
activejob (= 7.2.2.1)
activesupport (= 7.2.2.1)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (7.1.5.1)
actionview (= 7.1.5.1)
activesupport (= 7.1.5.1)
actionpack (7.2.2.1)
actionview (= 7.2.2.1)
activesupport (= 7.2.2.1)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack (>= 2.2.4, < 3.2)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.5.1)
actionpack (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
useragent (~> 0.16)
actiontext (7.2.2.1)
actionpack (= 7.2.2.1)
activerecord (= 7.2.2.1)
activestorage (= 7.2.2.1)
activesupport (= 7.2.2.1)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.5.1)
activesupport (= 7.1.5.1)
actionview (7.2.2.1)
activesupport (= 7.2.2.1)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.5.1)
activesupport (= 7.1.5.1)
activejob (7.2.2.1)
activesupport (= 7.2.2.1)
globalid (>= 0.3.6)
activemodel (7.1.5.1)
activesupport (= 7.1.5.1)
activerecord (7.1.5.1)
activemodel (= 7.1.5.1)
activesupport (= 7.1.5.1)
activemodel (7.2.2.1)
activesupport (= 7.2.2.1)
activerecord (7.2.2.1)
activemodel (= 7.2.2.1)
activesupport (= 7.2.2.1)
timeout (>= 0.4.0)
activestorage (7.1.5.1)
actionpack (= 7.1.5.1)
activejob (= 7.1.5.1)
activerecord (= 7.1.5.1)
activesupport (= 7.1.5.1)
activestorage (7.2.2.1)
actionpack (= 7.2.2.1)
activejob (= 7.2.2.1)
activerecord (= 7.2.2.1)
activesupport (= 7.2.2.1)
marcel (~> 1.0)
activesupport (7.1.5.1)
activesupport (7.2.2.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
tzinfo (~> 2.0, >= 2.0.5)
acts_as_list (1.2.4)
activerecord (>= 6.1)
activesupport (>= 6.1)
Expand Down Expand Up @@ -117,11 +111,6 @@ GEM
crass (1.0.6)
csv (3.3.5)
date (3.4.1)
delayed_job (4.1.13)
activesupport (>= 3.0, < 9.0)
delayed_job_active_record (4.1.11)
activerecord (>= 3.0, < 9.0)
delayed_job (>= 3.0, < 5)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -224,7 +213,6 @@ GEM
minitest (5.25.5)
msgpack (1.8.0)
multi_json (1.15.0)
mutex_m (0.3.0)
nenv (0.3.0)
net-http (0.6.0)
uri
Expand Down Expand Up @@ -275,20 +263,20 @@ GEM
rack (>= 1.3)
rackup (2.2.1)
rack (>= 3)
rails (7.1.5.1)
actioncable (= 7.1.5.1)
actionmailbox (= 7.1.5.1)
actionmailer (= 7.1.5.1)
actionpack (= 7.1.5.1)
actiontext (= 7.1.5.1)
actionview (= 7.1.5.1)
activejob (= 7.1.5.1)
activemodel (= 7.1.5.1)
activerecord (= 7.1.5.1)
activestorage (= 7.1.5.1)
activesupport (= 7.1.5.1)
rails (7.2.2.1)
actioncable (= 7.2.2.1)
actionmailbox (= 7.2.2.1)
actionmailer (= 7.2.2.1)
actionpack (= 7.2.2.1)
actiontext (= 7.2.2.1)
actionview (= 7.2.2.1)
activejob (= 7.2.2.1)
activemodel (= 7.2.2.1)
activerecord (= 7.2.2.1)
activestorage (= 7.2.2.1)
activesupport (= 7.2.2.1)
bundler (>= 1.15.0)
railties (= 7.1.5.1)
railties (= 7.2.2.1)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
Expand All @@ -300,10 +288,10 @@ GEM
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (7.1.5.1)
actionpack (= 7.1.5.1)
activesupport (= 7.1.5.1)
irb
railties (7.2.2.1)
actionpack (= 7.2.2.1)
activesupport (= 7.2.2.1)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
Expand Down Expand Up @@ -421,6 +409,7 @@ GEM
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.3)
useragent (0.16.11)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
Expand Down Expand Up @@ -452,8 +441,6 @@ DEPENDENCIES
byebug
cancancan (~> 3.2)
capybara (~> 3.39)
delayed_job (~> 4.1)
delayed_job_active_record (~> 4.1)
devise (~> 4.9)
foreman
guard
Expand All @@ -470,7 +457,7 @@ DEPENDENCIES
net-smtp
pg (~> 1.5)
puma (~> 6.4)
rails (~> 7.1.0)
rails (~> 7.2.0)
rails-controller-testing
redis (~> 5.0)
rubocop
Expand Down
91 changes: 29 additions & 62 deletions app/controllers/writing_sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,96 +1,74 @@
class WritingSessionsController < ApplicationController
protect_from_forgery with: :exception, if: Proc.new { |c| c.request.format != 'application/json' }
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
before_action :story
before_action :writing_session, only: [:show, :edit, :update, :destroy, :header_actions]
after_action :touch_story, only: [:create, :update, :destroy]
layout "home", only: [:new, :edit]
protect_from_forgery with: :exception, if: proc { |c| c.request.format != 'application/json' }
protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' }
after_action :touch_story, only: %i[create update destroy]
layout 'home', only: %i[new edit]

def index
unless can? :read, @story
redirect_to_home
end
load_and_authorize_resource :story
load_and_authorize_resource :writing_session, through: :story, shallow: true

def index
@writing_sessions = @story.writing_sessions.order(updated_at: :desc)
end

# GET /writing_sessions/1
# GET /writing_sessions/1.json
def show
unless can? :read, @session
redirect_to_home
end
end
def show; end

# GET /writing_sessions/new
def new
@title = 'Compose'
@session = @story.writing_sessions.create(user_id: current_user.id, text: "")
@writing_session = @story.writing_sessions.create(user_id: current_user.id, text: '')

redirect_to edit_story_writing_session_path(@story, @session.id)
redirect_to edit_story_writing_session_path(@story, @writing_session.id)
end

# GET /writing_sessions/1/edit
def edit
unless can? :update, @session
redirect_to_home
end
end
def edit; end

# POST /writing_sessions
# POST /writing_sessions.json
def create
unless can? :create, WritingSession
redirect_to_home
end

params = session_params
params[:text] = "<div>#{params[:text]}</div>"
text = "<div>#{writing_session_params[:text]}</div>"

@session = @story.writing_sessions.new params
@session.user_id = current_user.id
@session.word_count = @session.calculate_word_count
@writing_session = @story.writing_sessions.new(writing_session_params.merge(text:, user_id: current_user.id))
@writing_session.word_count = @writing_session.calculate_word_count

respond_to do |format|
if @session.save
format.html { redirect_to edit_story_writing_session_path(@story, @session.id), notice: 'Session was successfully created.', status: :see_other }
format.json { render json: @session, status: :ok }
if @writing_session.save
format.html do
redirect_to edit_story_writing_session_path(@story, @writing_session.id), notice: 'Session was successfully created.',
status: :see_other
end
format.json { render json: @writing_session, status: :ok }
else
format.html { render :new }
format.json { render json: @session.errors, status: :unprocessable_entity }
format.json { render json: @writing_session.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /writing_sessions/1
# PATCH/PUT /writing_sessions/1.json
def update
unless can? :update, @session
redirect_to_home
end

@session.text += "<div>#{session_params[:text]}</div>"
@session.word_count = @session.calculate_word_count
@writing_session.text += "<div>#{writing_session_params[:text]}</div>"
@writing_session.word_count = @writing_session.calculate_word_count

respond_to do |format|
if @session.save
format.html { redirect_to edit_story_writing_session_path(@story, @session.id), status: :see_other }
format.json { render json: @session, status: :ok }
if @writing_session.save
format.html { redirect_to edit_story_writing_session_path(@story, @writing_session.id), status: :see_other }
format.json { render json: @writing_session, status: :ok }
else
format.html { render :edit }
format.json { render json: @session.errors, status: :unprocessable_entity }
format.json { render json: @writing_session.errors, status: :unprocessable_entity }
end
end
end

# DELETE /writing_sessions/1
# DELETE /writing_sessions/1.json
def destroy
unless can? :destroy, @session
redirect_to_home
end

@session.destroy
@writing_session.destroy
respond_to do |format|
format.html { redirect_to story_path(@story), notice: 'Session was successfully destroyed.', status: :see_other }
format.json { head :no_content }
Expand All @@ -99,19 +77,8 @@ def destroy

private

# Use callbacks to share common setup or constraints between actions.
def writing_session
@session = @story.writing_sessions.find(params[:id])
end

def story
@story = current_user.stories.find(params[:story_id])
rescue ActiveRecord::RecordNotFound
redirect_to_home
end

# Only allow a list of trusted parameters through.
def session_params
def writing_session_params
params.require(:writing_session).permit(:text)
end

Expand Down
5 changes: 1 addition & 4 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def initialize(user)
#
return unless user.present?

if user.admin_role?
can :manage, :all
can :access, :blazer
end
can :access, :blazer if user.admin_role?

can :manage, WritingSession, user_id: user.id
can :manage, Story, user_id: user.id
Expand Down
Loading