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 %>
- <% type_options = [['全部', ''], ['Add', Site.site_types[:add]], ['Personal', Site.site_types[:personal]], ['Common', Site.site_types[:common]]] %> + <% type_options = [['全部', ''], ['Add', Site.site_types[:add]], ['Personal', Site.site_types[:personal]], ['Common', Site.site_types[:common]], ['Dict', Site.site_types[:dict]]] %> <%= select_tag(:site_type, options_for_select(type_options), class: 'form-control') %>
diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 019e3688..f2ee0fa7 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -1,31 +1,5 @@ json.setting do - # if @laboratory.present? - # setting = @laboratory.laboratory_setting - # json.name setting.name || default_setting.name - # json.nav_logo_url (setting.nav_logo_url || default_setting.nav_logo_url)&.[](1..-1) - # json.login_logo_url (setting.login_logo_url || default_setting.login_logo_url)&.[](1..-1) - # json.tab_logo_url (setting.tab_logo_url || default_setting.tab_logo_url)&.[](1..-1) - # - # json.subject_banner_url (setting.subject_banner_url || default_setting.subject_banner_url)&.[](1..-1) - # json.course_banner_url (setting.course_banner_url || default_setting.course_banner_url)&.[](1..-1) - # json.competition_banner_url (setting.competition_banner_url || default_setting.competition_banner_url)&.[](1..-1) - # json.moop_cases_banner_url (setting.moop_cases_banner_url || default_setting.moop_cases_banner_url)&.[](1..-1) - # json.oj_banner_url (setting.oj_banner_url || default_setting.oj_banner_url)&.[](1..-1) - # - # json.navbar setting.navbar || default_setting.navbar - # - # json.footer setting.footer || default_setting.footer - # - # end - nav_bar = default_setting.navbar - # if User.current.logged? - # nav_bar[2]["link"] = "/users/#{current_user.login}/projects" - # nav_bar[2]["hidden"] = false - # else - # nav_bar[2]["link"] = "" - # nav_bar[2]["hidden"] = true - # end if current_user && current_user.admin? nav_bar << manager_main_site_url end @@ -60,6 +34,11 @@ json.setting do end json.common @common + json.third_party @third_party + + json.professional_field do + json.array! @professional_fields + end if @top_system_notification.present? json.system_notification do diff --git a/config/initializers/gitlink_oauth_init.rb b/config/initializers/gitlink_oauth_init.rb new file mode 100644 index 00000000..c3733b80 --- /dev/null +++ b/config/initializers/gitlink_oauth_init.rb @@ -0,0 +1,16 @@ +oauth_config = {} +begin + config = Rails.application.config_for(:configuration) + oauth_config = config.dig('oauth', 'gitlink') + raise 'oauth educoder config missing' if oauth_config.blank? +rescue => ex + raise ex if Rails.env.production? + + puts %Q{\033[33m [warning] gitlink oauth config or configuration.yml missing, + please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} +end + +GitlinkOauth.client_id = oauth_config['client_id'] +GitlinkOauth.client_secret = oauth_config['client_secret'] +GitlinkOauth.base_url = oauth_config['base_url'] +GitlinkOauth.redirect_uri = oauth_config['redirect_uri']