Skip to content

Commit

Permalink
Merge branch 'master' into implementando-testes
Browse files Browse the repository at this point in the history
  • Loading branch information
leogiraldimg committed Dec 4, 2019
2 parents ab51b1a + 0f8a030 commit 794ddd8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ def isPageAdmin(college_id)
end
helper_method :isPageAdmin

def isUserAdminOfPage(college_id, user_id)
if College.exists?(user_id: user_id, id: college_id)
return true

elsif Administrator.exists?(user_id: user_id, college_id: college_id)
return true

else
return false
end
end
helper_method :isUserAdminOfPage
end
2 changes: 1 addition & 1 deletion src/app/app/controllers/college_whitelists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def verify_permission
# GET /college_whitelists.json
def index
if isPageAdmin(params[:college_id])
@college_whitelists = CollegeWhitelist.all
@college_whitelists = CollegeWhitelist.where(college_id: params[:college_id])
render :index
else
flash[:danger] = 'Área restrita. Você não é administrador da página.'
Expand Down
12 changes: 10 additions & 2 deletions src/app/app/controllers/colleges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ def create
@college.user = current_user
if @college.save
current_user.favorites << @college
flash[:sucess] = 'Faculdade cadastrada com sucesso'
redirect_to root_url
@cw = CollegeWhitelist.new(college: @college, user: current_user, status: "approved")
if @cw.save
flash[:sucess] = 'Faculdade cadastrada com sucesso'
redirect_to root_url
else
flash[:danger] = 'Ocorreu um erro com o cadastro'
render 'new'
end
else
render 'new'
end
Expand Down Expand Up @@ -63,6 +69,8 @@ def update

def destroy
@college = College.find(params[:id])
@college_whitelist = CollegeWhitelist.find_by(college_id: @college.id)
@college_whitelist.destroy
@college.destroy
notice = "A página do(a) #{@college.name} foi deletada."
flash[:success] = notice
Expand Down
4 changes: 3 additions & 1 deletion src/app/app/views/college_whitelists/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
<% if (college_whitelist.status == 'approved') %>
<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>
<% 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>
<% end %>
</tr>
<% end %>
<% end %>
Expand Down
Binary file modified src/app/tmp/cache/bootsnap-load-path-cache
Binary file not shown.

0 comments on commit 794ddd8

Please sign in to comment.