diff --git a/src/app/app/controllers/application_controller.rb b/src/app/app/controllers/application_controller.rb index 75a38010..1b77e84c 100644 --- a/src/app/app/controllers/application_controller.rb +++ b/src/app/app/controllers/application_controller.rb @@ -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 diff --git a/src/app/app/controllers/college_whitelists_controller.rb b/src/app/app/controllers/college_whitelists_controller.rb index bea39ef7..64fb5fbd 100644 --- a/src/app/app/controllers/college_whitelists_controller.rb +++ b/src/app/app/controllers/college_whitelists_controller.rb @@ -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.' diff --git a/src/app/app/controllers/colleges_controller.rb b/src/app/app/controllers/colleges_controller.rb index 0a83b7af..121e3b9e 100644 --- a/src/app/app/controllers/colleges_controller.rb +++ b/src/app/app/controllers/colleges_controller.rb @@ -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 @@ -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 diff --git a/src/app/app/views/college_whitelists/index.html.erb b/src/app/app/views/college_whitelists/index.html.erb index d42f1f30..9c20edeb 100644 --- a/src/app/app/views/college_whitelists/index.html.erb +++ b/src/app/app/views/college_whitelists/index.html.erb @@ -46,7 +46,9 @@ <% if (college_whitelist.status == 'approved') %> <%= college_whitelist.user.first_name + ' ' + college_whitelist.user.last_name %> - <%= 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" %> + <% if !isUserAdminOfPage(college_whitelist.college.id, college_whitelist.user.id) %> + <%= 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" %> + <% end %> <% end %> <% end %> diff --git a/src/app/tmp/cache/bootsnap-load-path-cache b/src/app/tmp/cache/bootsnap-load-path-cache index 0e9d7449..716b4438 100644 Binary files a/src/app/tmp/cache/bootsnap-load-path-cache and b/src/app/tmp/cache/bootsnap-load-path-cache differ