Skip to content

Commit

Permalink
Merge pull request #12 from leogiraldimg/removendo_cheiros_de_codigo
Browse files Browse the repository at this point in the history
Removendo cheiros de codigo
  • Loading branch information
leogiraldimg authored Dec 4, 2019
2 parents bcc7438 + 22c3f4c commit 55f477c
Show file tree
Hide file tree
Showing 6 changed files with 3,392 additions and 62 deletions.
47 changes: 13 additions & 34 deletions src/app/app/controllers/college_whitelists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CollegeWhitelistsController < ApplicationController
before_action :require_logged_in_user
before_action :set_college
before_action :set_college_whitelist, only: [:show, :edit, :update, :destroy]
before_action :set_college_whitelist, only: [:show, :edit, :destroy]

def verify_permission
if @college.request_to_participate == "0"
Expand All @@ -15,7 +15,7 @@ def verify_permission
# GET /college_whitelists.json
def index
if isPageAdmin(params[:college_id])
@college_whitelists = CollegeWhitelist.where(college_id: params[:college_id])
set_whitelist_by_college
render :index
else
flash[:danger] = 'Área restrita. Você não é administrador da página.'
Expand Down Expand Up @@ -50,38 +50,10 @@ def create
end
end

def revoke
@college_whitelist = CollegeWhitelist.find(params[:college_whitelist_id])
respond_to do |format|
if @college_whitelist.update(status: :pending)
format.html { redirect_to college_college_whitelists_path }
else
format.html {
flash[:danger] = "Não foi possível revogar a credencial do usuário para pendente."
render :index
}
end
end
end

def aprove
@college_whitelist = CollegeWhitelist.find(params[:college_whitelist_id])
respond_to do |format|
if @college_whitelist.update(status: :approved)
format.html { redirect_to college_college_whitelists_path }
else
format.html {
flash[:danger] = "Não foi possível alterar a credencial do usuário para aprovado."
render :index
}
end
end
end

def reject
@college_whitelist = CollegeWhitelist.find(params[:college_whitelist_id])
def update
@college_whitelist = CollegeWhitelist.find(params[:id])
respond_to do |format|
if @college_whitelist.update(status: :rejected)
if @college_whitelist.update(status: params[:college_whitelist][:status])
format.html { redirect_to college_college_whitelists_path }
else
format.html {
Expand All @@ -107,6 +79,10 @@ def college_whitelist_params
params.require(:college_whitelist).permit(:status)
end

def set_whitelist_by_college
@college_whitelists = CollegeWhitelist.where(college_id: params[:college_id])
end

def check_college_access_permission
@college_whitelist = CollegeWhitelist.find_by(user_id: current_user.id, college_id: @college.id)
if !@college_whitelist.nil?
Expand All @@ -128,5 +104,8 @@ def check_request_access_status(college_whitelist)
end
end


def return_status_enum(status)
p status
CollegeWhitelist.statuses[status]
end
end
8 changes: 4 additions & 4 deletions src/app/app/views/college_whitelists/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<td class="column-name"><%= college_whitelist.user.first_name + ' ' + college_whitelist.user.last_name %></td>
<td class="column-btn">
<div class="btn-area">
<%= button_to 'Aprovar', { action: "aprove", :college_whitelist => {:status => college_whitelist.status}, :college_id => college_whitelist.college.id, :college_whitelist_id => college_whitelist.id }, method: "patch", class: "botao super small" %>
<%= button_to 'Rejeitar', { action: "reject", :college_whitelist => {:status => college_whitelist.status}, :college_id => college_whitelist.college.id, :college_whitelist_id => college_whitelist.id }, method: "patch", class: "botao super small" %>
<%= button_to 'Aprovar', { action: "update", :college_whitelist => {:status => :approved}, :college_id => college_whitelist.college_id, :id => college_whitelist.id}, method: "patch", class: "botao super small" %>
<%= button_to 'Rejeitar', { action: "update", :college_whitelist => {:status => :rejected}, :college_id => college_whitelist.college_id, :id => college_whitelist.id}, method: "patch", class: "botao super small" %>
</div>
</td>
</tr>
Expand All @@ -47,7 +47,7 @@
<tr>
<td class="column-name"><%= college_whitelist.user.first_name + ' ' + college_whitelist.user.last_name %></td>
<% if !isUserAdminOfPage(college_whitelist.college.id, college_whitelist.user.id) %>
<td class="column-btn"><%= button_to 'Revogar', { action: "revoke", :college_whitelist => {:status => college_whitelist.status}, :college_id => college_whitelist.college.id, :college_whitelist_id => college_whitelist.id }, method: "patch", class: "botao super small" %></td>
<td class="column-btn"><%= button_to 'Revogar', { action: "update", :college_whitelist => {:status => :pending}, :college_id => college_whitelist.college_id, :id => college_whitelist.id}, method: "patch", class: "botao super small" %></td>
<% end %>
</tr>
<% end %>
Expand All @@ -70,7 +70,7 @@
<% if (college_whitelist.status == 'rejected') %>
<tr>
<td class="column-name"><%= college_whitelist.user.first_name + ' ' + college_whitelist.user.last_name %></td>
<td class="column-btn"><%= button_to 'Revogar', { action: "revoke", :college_whitelist => {:status => college_whitelist.status}, :college_id => college_whitelist.college.id, :college_whitelist_id => college_whitelist.id }, method: "patch", class: "botao super small" %></td>
<td class="column-btn"><%= button_to 'Revogar', { action: "update", :college_whitelist => {:status => :pending}, :college_id => college_whitelist.college_id, :id => college_whitelist.id}, method: "patch", class: "botao super small" %></td>
</tr>
<% end %>
<% end %>
Expand Down
7 changes: 1 addition & 6 deletions src/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@
end

resources :colleges, only: [:new, :create, :show, :index, :edit, :update] do
resources :college_whitelists, only: [:new, :create, :index] do
patch 'aprove', to: 'college_whitelists#aprove'
patch 'reject', to: 'college_whitelists#reject'
patch 'revoke', to: 'college_whitelists#revoke'
end
resources :college_whitelists, only: [:new, :create, :index, :update]
get 'verify_permission', to: 'college_whitelists#verify_permission'

end

resources :spotteds, only: [:new, :create, :show, :index] do
Expand Down
37 changes: 19 additions & 18 deletions src/app/features/step_definitions/edit_page_settings_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@
visit edit_college_path(@college, :id => @college.id)
end

When(/^I fill the edit page settings form$/) do
fill_in "college[background_color]", with: "#fafafa"
fill_in "college[background_image]", with: ""
fill_in "college[font_family]", with: "Arial"
fill_in "college[font_color]", with: "#000000"
select 'Manual', from: "college[admin_approves_spotted]"
select 'Sim', from: "college[request_to_participate]"
end

Then(/^I should see the green success toast$/) do
expect(page).to have_xpath('.//div[@class="alert alert-success alert-dismissible"]')
end

When(/^I fill the edit page settings form$/) do
steps %Q{
Given I fill general info of college
}
fill_in "college[background_image]", with: ""
end

When(/^I fill the edit page settings form including background_image field$/) do
fill_in "college[background_color]", with: "#fafafa"
fill_in "college[background_image]", with: "https://townsquare.media/site/366/files/2019/04/Sabaton1.jpg?w=980&q=75"
fill_in "college[font_family]", with: "Arial"
fill_in "college[font_color]", with: "#000000"
select 'Manual', from: "college[admin_approves_spotted]"
select 'Sim', from: "college[request_to_participate]"
steps %Q{
Given I fill general info of college
}
end

When(/^I fill the edit page settings form except font_family field$/) do
steps %Q{
Given I fill general info of college
}
fill_in "college[font_family]", with: ""
end

Given (/^I fill general info of college$/) do
fill_in "college[background_color]", with: "#fafafa"
fill_in "college[background_image]", with: "https://townsquare.media/site/366/files/2019/04/Sabaton1.jpg?w=980&q=75"
fill_in "college[font_family]", with: ""
fill_in "college[font_family]", with: "Arial"
fill_in "college[font_color]", with: "#000000"
select 'Manual', from: "college[admin_approves_spotted]"
select 'Sim', from: "college[request_to_participate]"
end

end
Loading

0 comments on commit 55f477c

Please sign in to comment.