FIX 完善gitea平台修改用户信息接口
This commit is contained in:
parent
ae2c6627a9
commit
e6396bdefd
|
@ -0,0 +1,11 @@
|
|||
class Gitea::User::UpdateForm
|
||||
include ActiveModel::Model
|
||||
EMAIL_REGEX = /^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9_\-.]+(\.[a-zA-Z0-9_-]+)+$/
|
||||
|
||||
attr_accessor :username, :email, :admin, :allow_create_organization, :allow_git_hook, :allow_import_local,
|
||||
:full_name, :location, :login_name, :max_repo_creation, :must_change_password, :password, :prohibit_login,
|
||||
:source_id, :website
|
||||
|
||||
validates :username, presence: true
|
||||
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
||||
end
|
|
@ -0,0 +1,49 @@
|
|||
module Gitea::User
|
||||
class UpdateInteractor
|
||||
def self.call(username, params={})
|
||||
interactor = new(username, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(username, params)
|
||||
@username = username
|
||||
@params = params
|
||||
end
|
||||
|
||||
def success?
|
||||
@error.nil?
|
||||
end
|
||||
|
||||
def result
|
||||
@result
|
||||
end
|
||||
|
||||
def run
|
||||
Gitea::User::UpdateForm.new(valid_params).validate!
|
||||
response = Gitea::User::UpdateService.new(username, params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||
fail!(exception.message)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
attr_reader :params, :username
|
||||
|
||||
def fail!(error)
|
||||
@error = error
|
||||
end
|
||||
|
||||
def render_result(response)
|
||||
@result = response
|
||||
end
|
||||
|
||||
def valid_params
|
||||
@params.merge(username: username)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,5 @@
|
|||
class Gitea::User::UpdateService < Gitea::ClientService
|
||||
# attr_reader :admin_user, :params
|
||||
attr_reader :token, :old_login, :params
|
||||
attr_reader :edit_username, :params
|
||||
# 只有管理员才能修改用户信息
|
||||
# params:
|
||||
# admin boolean
|
||||
|
@ -18,10 +17,10 @@ class Gitea::User::UpdateService < Gitea::ClientService
|
|||
# source_id integer($int64)
|
||||
# website string
|
||||
|
||||
def initialize(token, old_login, params={})
|
||||
@token = token
|
||||
@params = params
|
||||
@old_login = old_login
|
||||
def initialize(edit_username, params={}, token=nil)
|
||||
@token = token
|
||||
@params = params
|
||||
@edit_username = edit_username
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -31,7 +30,7 @@ class Gitea::User::UpdateService < Gitea::ClientService
|
|||
private
|
||||
|
||||
def url
|
||||
"/admin/users/#{old_login}"
|
||||
"/admin/users/#{edit_username}"
|
||||
end
|
||||
|
||||
def data_params
|
||||
|
|
Loading…
Reference in New Issue