diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6c28271db..3f7cd4170 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -285,7 +285,8 @@ class UsersController < ApplicationController :gender, :location, :location_city, :occupation, :technical_title, :school_id, :department_id, :province, :city, - :custom_department, :identity, :student_id, :description] + :custom_department, :identity, :student_id, :description, + :show_email, :show_location, :show_department] ) end diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 5771f757f..72bf724a5 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -1,7 +1,7 @@ # Users @@ -66,13 +66,17 @@ await octokit.request('PATCH/PUT /api/users/:login.json') ### 请求字段说明: 参数 | 类型 | 字段说明 --------- | ----------- | ----------- -|user.nickname |string |用户昵称 | -|user.image |string/file |用户头像 | +|user.nickname |string |用户昵称 | +|user.image |base64/file |用户头像 | |user.user_extension_attributes.gender |int |性别, 0男 1女 | |user.user_extension_attributes.province |string |省份 | |user.user_extension_attributes.city |string |城市 | -|user.user_extension_attributes.description |string |个性签名 | +|user.user_extension_attributes.description |string |简介 | |user.user_extension_attributes.custom_department|string |单位名称 | +|user.user_extension_attributes.technical_title |string |职业 | +|user.user_extension_attributes.show_email |bool |是否展示邮箱 | +|user.user_extension_attributes.show_location |bool |是否展示位置 | +|user.user_extension_attributes.show_department |bool |是否展示公司 | > 请求的JSON示例: diff --git a/app/models/user.rb b/app/models/user.rb index e190e82ea..09880b8cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -181,7 +181,9 @@ class User < Owner attr_accessor :password, :password_confirmation - delegate :description, :gender, :department_id, :school_id, :location, :location_city, :technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true + delegate :description, :gender, :department_id, :school_id, :location, :location_city, + :show_email, :show_location, :show_department, + :technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true before_save :update_hashed_password after_create do diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 56eed12bd..47b27c08b 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -25,6 +25,9 @@ # province :string(255) # city :string(255) # custom_department :string(255) +# show_email :boolean default("0") +# show_location :boolean default("0") +# show_department :boolean default("0") # # Indexes # diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder index 560c207d6..06fab129f 100644 --- a/app/views/users/show.json.jbuilder +++ b/app/views/users/show.json.jbuilder @@ -19,8 +19,8 @@ json.common_projects_count @projects_common_count json.mirror_projects_count @projects_mirrior_count json.sync_mirror_projects_count @projects_sync_mirrior_count json.created_time format_time(@user.created_on) -json.email @user.mail -json.province @user.province -json.city @user.city -json.custom_department @user.custom_department +json.email @user.show_email ? @user.mail : nil +json.province @user.show_location ? @user.province : nil +json.city @user.show_location ? @user.city : nil +json.custom_department @user.show_department ? @user.custom_department : nil json.description @user.description \ No newline at end of file diff --git a/db/migrate/20210603020327_add_show_condition_to_user_extensions.rb b/db/migrate/20210603020327_add_show_condition_to_user_extensions.rb new file mode 100644 index 000000000..e64da0b71 --- /dev/null +++ b/db/migrate/20210603020327_add_show_condition_to_user_extensions.rb @@ -0,0 +1,7 @@ +class AddShowConditionToUserExtensions < ActiveRecord::Migration[5.2] + def change + add_column :user_extensions, :show_email, :boolean, default: false + add_column :user_extensions, :show_location, :boolean, default: false + add_column :user_extensions, :show_department, :boolean, default: false + end +end diff --git a/public/docs/api.html b/public/docs/api.html index c8fa29fa2..0cf007cf1 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -617,7 +617,7 @@ Success — a happy kitten is an authenticated kitten!

Users

获取当前登陆用户信息

@@ -704,7 +704,7 @@ Success — a happy kitten is an authenticated kitten! user.image -string/file +base64/file 用户头像 @@ -725,13 +725,33 @@ Success — a happy kitten is an authenticated kitten! user.user_extension_attributes.description string -个性签名 +简介 user.user_extension_attributes.custom_department string 单位名称 + +user.user_extension_attributes.technical_title +string +职业 + + +user.user_extension_attributes.show_email +bool +是否展示邮箱 + + +user.user_extension_attributes.show_location +bool +是否展示位置 + + +user.user_extension_attributes.show_department +bool +是否展示公司 +