From da987880313b3779e1d3689a49705fcbed23d117 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Fri, 2 Jun 2017 15:39:10 +0200 Subject: [PATCH] small code fixes --- app/assets/javascripts/repositories/index.js | 10 +++++----- app/controllers/repositories_controller.rb | 3 +-- app/helpers/permission_helper.rb | 2 +- app/views/repositories/index.html.erb | 10 ++++------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index 6ae014ec6..e7054d012 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -11,7 +11,7 @@ function init() { } function initCreateNewModal() { - var link = $("[data-action='create-new-repository']"); + var link = $("#create-new-repository"); var modal = $("#create-new-modal"); var submitBtn = modal.find(".modal-footer [data-action='submit']"); @@ -25,13 +25,13 @@ function initCreateNewModal() { modalBody.html(data.html); modalBody.find("form") - .on("ajax:success", function(ev2, data2, status2) { + .on("ajax:success", function(ev, data, status) { // Redirect to index page - $(location).attr("href", data2.url); + $(location).attr("href", data.url); }) - .on("ajax:error", function(ev2, data2, status2) { + .on("ajax:error", function(ev, data, status) { // Display errors if needed - $(this).renderFormErrors("repository", data2.responseJSON); + $(this).renderFormErrors("repository", data.responseJSON); }); modal.modal("show"); diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d048601ba..23c53bdfb 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -115,8 +115,7 @@ class RepositoriesController < ApplicationController end def check_create_permissions - render_403 unless can_create_new_repository(@team) && - @repositories.count < Constants::REPOSITORIES_LIMIT + render_403 unless can_create_new_repository(@team) end def check_edit_and_destroy_permissions diff --git a/app/helpers/permission_helper.rb b/app/helpers/permission_helper.rb index 3ed492cac..ba187f99d 100644 --- a/app/helpers/permission_helper.rb +++ b/app/helpers/permission_helper.rb @@ -1054,7 +1054,7 @@ module PermissionHelper end def can_create_new_repository(team) - is_admin_of_team(team) + is_admin_of_team(team) && team.repositories.count < Constants::REPOSITORIES_LIMIT end def can_view_repositories(team) diff --git a/app/views/repositories/index.html.erb b/app/views/repositories/index.html.erb index 34bb7d88e..40a107bc5 100644 --- a/app/views/repositories/index.html.erb +++ b/app/views/repositories/index.html.erb @@ -3,6 +3,7 @@ <% if current_team %> <%= render partial: "repositories/breadcrumbs.html.erb", locals: { teams: @teams, current_team: current_team, type: @type } %> + <%= render partial: "repositories/index/create_new_modal.html.erb" %> <% active_repo = @repositories.find_by_id(params[:repository]) %> <% active_repo = @repositories.first if !active_repo %> @@ -19,15 +20,13 @@ <% end %>
  • + <% unless can_create_new_repository(current_team) %> class="disabled" <% end %>> - data-action='create-new-repository' + <% if can_create_new_repository(current_team) %> + id='create-new-repository' <% end %>> @@ -88,4 +87,3 @@ <% end %> <%= javascript_include_tag "repositories/index", "data-turbolinks-track" => true %> -<%= render partial: "repositories/index/create_new_modal.html.erb" %>