-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,088 additions
and
180 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 |
---|---|---|
@@ -1 +1 @@ | ||
2.5.1 | ||
2.5.1 |
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
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
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Web | ||
module Dashboard | ||
# Manage votes to ideas | ||
class VotesController < BaseController | ||
before_action :idea_find, only: %i[index up down] | ||
rescue_from Pundit::NotAuthorizedError, with: :redirect_to_dashboard_idea | ||
|
||
def index | ||
@votes = @idea.votes | ||
end | ||
|
||
def up | ||
Ops::Idea::Vote.call(idea: @idea, user: current_user, vote_type: 'up') | ||
redirect_to dashboard_idea_url(@idea), | ||
flash: { success: t('dashboard.votes.notice.success') } | ||
end | ||
|
||
def down | ||
Ops::Idea::Vote.call(idea: @idea, user: current_user, vote_type: 'down') | ||
redirect_to dashboard_idea_url(@idea), | ||
flash: { success: t('dashboard.votes.notice.success') } | ||
end | ||
|
||
private | ||
|
||
def idea_find | ||
@idea ||= ::Idea.find(params[:idea_id]) | ||
authorize @idea, policy_class: ::Dashboard::VotePolicy | ||
end | ||
|
||
def redirect_to_dashboard_idea | ||
redirect_to dashboard_idea_url(@idea), | ||
flash: { warning: t('dashboard.votes.notice.warning') } | ||
end | ||
end | ||
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
# This is the voting class for ideas | ||
class Vote < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :idea | ||
|
||
validates :vote_type, presence: true | ||
|
||
scope :up, -> { where(vote_type: 'up') } | ||
scope :down, -> { where(vote_type: 'down') } | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ops | ||
module Idea | ||
# This is the operation of creating a vote for the idea | ||
class Vote < BaseOperation | ||
step :create_vote! | ||
|
||
private | ||
|
||
def create_vote!(_ctx, idea:, user:, vote_type:, **) | ||
::Vote.create!(vote_type: vote_type, user: user, idea: idea) | ||
end | ||
end | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ops | ||
module Idea | ||
# Operation activate idea | ||
class Voting < BaseOperation | ||
step :change_state! | ||
|
||
private | ||
|
||
def change_state!(_ctx, idea:, **) | ||
idea.voting! | ||
end | ||
end | ||
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dashboard | ||
# Voting policy for an idea | ||
class VotePolicy < DashboardPolicy | ||
def index? | ||
true | ||
end | ||
|
||
def up? | ||
current_user_allow_voting? | ||
end | ||
|
||
alias down? up? | ||
|
||
def voting? | ||
record.voting? | ||
end | ||
|
||
private | ||
|
||
def current_user_allow_voting? | ||
developer? && user.votes.where(idea_id: record.id).empty? && record.voting? | ||
end | ||
end | ||
end |
Oops, something went wrong.