diff --git a/app/controllers/admins/project_ignores_controller.rb b/app/controllers/admins/project_ignores_controller.rb index 360f189c0..6450f6afc 100644 --- a/app/controllers/admins/project_ignores_controller.rb +++ b/app/controllers/admins/project_ignores_controller.rb @@ -1,6 +1,6 @@ class Admins::ProjectIgnoresController < Admins::BaseController before_action :set_ignore, only: [:edit,:update, :destroy,:show] - before_action :validate_params, only: [:create, :update] + # before_action :validate_params, only: [:create, :update] def index sort_by = Ignore.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' @@ -31,12 +31,12 @@ class Admins::ProjectIgnoresController < Admins::BaseController # } @project_ignore = Ignore.new(ignore_params) - if @project_ignore.save! + if @project_ignore.save redirect_to admins_project_ignores_path flash[:success] = "创建成功" else - render :new - flash[:danger] = "创建失败" + redirect_to admins_project_ignores_path + flash[:danger] = @project_ignore.errors.full_messages.join(",") end end @@ -58,8 +58,8 @@ class Admins::ProjectIgnoresController < Admins::BaseController redirect_to admins_project_ignores_path flash[:success] = "更新成功" else - render :edit - flash[:danger] = "更新失败" + redirect_to admins_project_ignores_path + flash[:danger] = @project_ignore.errors.full_messages.join(",") end end @@ -98,23 +98,23 @@ class Admins::ProjectIgnoresController < Admins::BaseController params.require(:ignore).permit(:name,:content) end - def validate_params - name = params[:ignore][:name] - if name.blank? - flash[:danger] = "名称不允许为空" - redirect_to admins_project_ignores_path - elsif check_ignore_present?(name) && @project_ignore.blank? - flash[:danger] = "创建失败:名称已存在" - redirect_to admins_project_ignores_path - end - end + # def validate_params + # name = params[:ignore][:name] + # if name.blank? + # flash[:danger] = "名称不允许为空" + # redirect_to admins_project_ignores_path + # elsif check_ignore_present?(name) && @project_ignore.blank? + # flash[:danger] = "创建失败:名称已存在" + # redirect_to admins_project_ignores_path + # end + # end - def check_ignore_present?(name) - return true if name.blank? - name_downcase = name.downcase - name_upcase = name.upcase - name_first_big = name.capitalize - Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big) - end + # def check_ignore_present?(name) + # return true if name.blank? + # name_downcase = name.downcase + # name_upcase = name.upcase + # name_first_big = name.capitalize + # Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big) + # end end diff --git a/app/controllers/admins/project_languages_controller.rb b/app/controllers/admins/project_languages_controller.rb index 0f26f25bb..69594eb50 100644 --- a/app/controllers/admins/project_languages_controller.rb +++ b/app/controllers/admins/project_languages_controller.rb @@ -27,17 +27,18 @@ class Admins::ProjectLanguagesController < Admins::BaseController flash[:success] = '创建成功' else redirect_to admins_project_languages_path - flash[:danger] = '创建失败' + flash[:danger] = @project_language.errors.full_messages.join(",") end end def update - if @project_language.update_attribute(:name, @name) + @project_language.attributes = {name: @name} + if @project_language.save redirect_to admins_project_languages_path flash[:success] = '更新成功' else redirect_to admins_project_languages_path - flash[:success] = '更新失败' + flash[:danger] = @project_language.errors.full_messages.join(",") end end diff --git a/app/controllers/admins/project_licenses_controller.rb b/app/controllers/admins/project_licenses_controller.rb index 5c16a884b..44ae75118 100644 --- a/app/controllers/admins/project_licenses_controller.rb +++ b/app/controllers/admins/project_licenses_controller.rb @@ -1,6 +1,6 @@ class Admins::ProjectLicensesController < Admins::BaseController before_action :set_license, only: [:edit,:update, :destroy,:show] - before_action :validate_params, only: [:create, :update] + # before_action :validate_params, only: [:create, :update] def index sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' @@ -30,13 +30,12 @@ class Admins::ProjectLicensesController < Admins::BaseController # position: max_position # } @project_license = License.new(license_params) - - if @project_license.save! + if @project_license.save redirect_to admins_project_licenses_path flash[:success] = "创建成功" else - render :new - flash[:danger] = "创建失败" + redirect_to admins_project_licenses_path + flash[:danger] = @project_license.errors.full_messages.join(",") end end @@ -54,12 +53,13 @@ class Admins::ProjectLicensesController < Admins::BaseController # permissions: permissions.to_s, # limitations: limitations.to_s # } - if @project_license.update_attributes(license_params) + @project_license.attributes = license_params + if @project_license.save redirect_to admins_project_licenses_path flash[:success] = "更新成功" else - render :edit - flash[:danger] = "更新失败" + render admins_project_licenses_path + flash[:danger] = @project_license.errors.full_messages.join(",") end end @@ -98,23 +98,23 @@ class Admins::ProjectLicensesController < Admins::BaseController params.require(:license).permit(:name,:content) end - def validate_params - name = params[:license][:name] - if name.blank? - flash[:danger] = "名称不允许为空" - redirect_to admins_project_licenses_path - elsif check_license_present?(name) && @project_license.blank? - flash[:danger] = "创建失败:名称已存在" - redirect_to admins_project_licenses_path - end - end + # def validate_params + # name = params[:license][:name] + # if name.blank? + # flash[:danger] = "名称不允许为空" + # redirect_to admins_project_licenses_path + # elsif check_license_present?(name) && @project_license.blank? + # flash[:danger] = "创建失败:名称已存在" + # redirect_to admins_project_licenses_path + # end + # end - def check_license_present?(name) - return true if name.blank? - name_downcase = name.downcase - name_upcase = name.upcase - name_first_big = name.capitalize - License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big) - end + # def check_license_present?(name) + # return true if name.blank? + # name_downcase = name.downcase + # name_upcase = name.upcase + # name_first_big = name.capitalize + # License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big) + # end end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 5c8ed963e..92eb68f35 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -65,13 +65,13 @@ class MembersController < ApplicationController def check_member_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take - return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) + return render_error("#{@user&.nickname}已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) end def check_member_not_exists! @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists? - return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists? + return render_error("#{@user&.nickname}还不是项目成员") unless member_exists? end def check_user_profile_completed diff --git a/app/models/ignore.rb b/app/models/ignore.rb index a6dc9a5ac..7220ee75d 100644 --- a/app/models/ignore.rb +++ b/app/models/ignore.rb @@ -11,4 +11,7 @@ class Ignore < ApplicationRecord include Projectable + + validates :name, :content, presence: true + validates :name, uniqueness: { case_sensitive: false } end diff --git a/app/models/license.rb b/app/models/license.rb index 0a14fb85e..d14a9db14 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -11,4 +11,8 @@ class License < ApplicationRecord include Projectable + + validates :name, :content, presence: true + validates :name, uniqueness: { case_sensitive: false } + end diff --git a/app/models/project_language.rb b/app/models/project_language.rb index ced6c5f9e..09b0b80f2 100644 --- a/app/models/project_language.rb +++ b/app/models/project_language.rb @@ -12,4 +12,6 @@ class ProjectLanguage < ApplicationRecord include Projectable + + validates :name, uniqueness: true end diff --git a/app/views/admins/project_categories/_form_modal.html.erb b/app/views/admins/project_categories/_form_modal.html.erb index fc58d3345..3ad6e044c 100644 --- a/app/views/admins/project_categories/_form_modal.html.erb +++ b/app/views/admins/project_categories/_form_modal.html.erb @@ -21,6 +21,7 @@ <%= p.number_field :pinned_index,class: "form-control input-lg",placeholder: "精选等级",required: true%> + <%if false%>
<% logo_img = @project_category.logo_url %>
@@ -34,6 +35,7 @@
尺寸:高度38px以内,宽等比例缩放
+ <% end %>