diff --git a/app/controllers/owners_controller.rb b/app/controllers/owners_controller.rb index 28a5210d..067fe4da 100644 --- a/app/controllers/owners_controller.rb +++ b/app/controllers/owners_controller.rb @@ -12,7 +12,7 @@ class OwnersController < ApplicationController def show @owner = Owner.find_by(login: params[:id]) || Owner.find_by(id: params[:id]) - return render_not_found unless @owner.present? + # return render_not_found unless @owner.present? # 组织 if @owner.is_a?(Organization) return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 95224353..d2752cff 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -5,6 +5,8 @@ class SettingsController < ApplicationController get_add_menu get_common_menu get_personal_menu + get_third_party + get_professional_fields get_top_system_notification end @@ -49,6 +51,29 @@ class SettingsController < ApplicationController end end + def get_third_party + @third_party = [] + @third_party << { + name: 'GitLink', + url: GitlinkOauth.oauth_url + } + @third_party << { + name: 'Openkyin', + url: GitlinkOauth.oauth_url + } + end + + def get_professional_fields + # @professional_fields = Site.dict + + if Site.dict.count == 0 + "自动化、计算机、机械、材料、航空航天、电子信息、电气、医学、建筑、理学、教育、管理、其他".split("、").each_with_index do |key,index| + Site.dict.create!(name: key, url: index, key: "professional_field") + end + end + @professional_fields = Site.get_dict_data("professional_field") + end + def get_top_system_notification @top_system_notification = SystemNotification.is_top.first end diff --git a/app/libs/gitlink_oauth.rb b/app/libs/gitlink_oauth.rb new file mode 100644 index 00000000..f07602a9 --- /dev/null +++ b/app/libs/gitlink_oauth.rb @@ -0,0 +1,18 @@ +module GitlinkOauth + class << self + attr_accessor :client_id, :client_secret, :base_url, :redirect_uri + + def logger + @_logger ||= STDOUT + end + + def logger=(l) + @_logger = l + end + + def oauth_url + "#{base_url}/oauth2?call_url=/oauth/authorize?client_id=#{client_id}&redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&response_type=code" + end + + end +end \ No newline at end of file diff --git a/app/models/site.rb b/app/models/site.rb index af5e7816..771090a6 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -15,9 +15,10 @@ class Site < ApplicationRecord # add: 添加类链接 # personal: 个人名下类链接, # common: 普通链接 - enum site_type: { add: 0, personal: 1, common: 2 } + # dict: 字典类型 + enum site_type: { add: 0, personal: 1, common: 2, dict: 3 } - scope :by_search, -> (keyword){ where("name LIKE :keyword OR url LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? } + scope :by_search, -> (keyword){ where("name LIKE :keyword OR url LIKE :keyword OR `key` LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? } scope :by_site_type, -> (site_type){ where(site_type: strip_param(site_type)) unless strip_param(site_type).blank? } def self.set_default_menu @@ -76,4 +77,13 @@ class Site < ApplicationRecord end } end + + def self.get_dict_data(type) + professional_fields =[] + Site.dict.where(key: type).select(:name, :url).each do |site| + hash = { name: "#{site.name}", value: "#{site.url}" } + professional_fields << hash + end + professional_fields + end end diff --git a/app/queries/admins/user_query.rb b/app/queries/admins/user_query.rb index 5a49bf14..0c8144fe 100644 --- a/app/queries/admins/user_query.rb +++ b/app/queries/admins/user_query.rb @@ -36,6 +36,9 @@ class Admins::UserQuery < ApplicationQuery # 单位 users = users.where("company_name LIKE :name ", name: "%#{params[:company_name]}%") if params[:company_name].present? + # 专业领域 + users = users.where(professional_field: params[:professional_field]) if params[:professional_field].present? + # 授权类型 if params[:auto_trial].present? users = users.joins(user_extension: :school).where(schools: { auto_users_trial: params[:auto_trial].to_i == 1 }) diff --git a/app/views/admins/sites/index.html.erb b/app/views/admins/sites/index.html.erb index 8a5fa1bf..a8edc0c9 100644 --- a/app/views/admins/sites/index.html.erb +++ b/app/views/admins/sites/index.html.erb @@ -6,7 +6,7 @@ <%= form_tag(admins_sites_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>