diff options
author | beatrix <beatrix.bitrot@gmail.com> | 2017-09-09 20:11:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-09 20:11:48 -0400 |
commit | 3dff74eecf5387b92b862893248710d2efb90eec (patch) | |
tree | 0d29d8c952a0c62e7de4348a1d63963fd5eca237 /app/controllers/settings | |
parent | e18ed4bbc7ab4e258d05a3e2a5db0790f67a8f37 (diff) | |
parent | 14e1fb8d36763e5255e7b8e440ecaf02208db004 (diff) |
Merge pull request #141 from yipdw/sync/upstream
Sync with upstream @ v1.6.0rc3 ohhhhhhhhhhh heck here we go
Diffstat (limited to 'app/controllers/settings')
-rw-r--r-- | app/controllers/settings/applications_controller.rb | 72 | ||||
-rw-r--r-- | app/controllers/settings/profiles_controller.rb | 3 |
2 files changed, 74 insertions, 1 deletions
diff --git a/app/controllers/settings/applications_controller.rb b/app/controllers/settings/applications_controller.rb new file mode 100644 index 000000000..8fc9a0fa9 --- /dev/null +++ b/app/controllers/settings/applications_controller.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +class Settings::ApplicationsController < ApplicationController + layout 'admin' + + before_action :authenticate_user! + before_action :set_application, only: [:show, :update, :destroy, :regenerate] + before_action :prepare_scopes, only: [:create, :update] + + def index + @applications = current_user.applications.page(params[:page]) + end + + def new + @application = Doorkeeper::Application.new( + redirect_uri: Doorkeeper.configuration.native_redirect_uri, + scopes: 'read write follow' + ) + end + + def show; end + + def create + @application = current_user.applications.build(application_params) + + if @application.save + redirect_to settings_applications_path, notice: I18n.t('applications.created') + else + render :new + end + end + + def update + if @application.update(application_params) + redirect_to settings_applications_path, notice: I18n.t('generic.changes_saved_msg') + else + render :show + end + end + + def destroy + @application.destroy + redirect_to settings_applications_path, notice: I18n.t('applications.destroyed') + end + + def regenerate + @access_token = current_user.token_for_app(@application) + @access_token.destroy + + redirect_to settings_application_path(@application), notice: I18n.t('applications.token_regenerated') + end + + private + + def set_application + @application = current_user.applications.find(params[:id]) + end + + def application_params + params.require(:doorkeeper_application).permit( + :name, + :redirect_uri, + :scopes, + :website + ) + end + + def prepare_scopes + scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil) + params[:doorkeeper_application][:scopes] = scopes.join(' ') if scopes.is_a? Array + end +end diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index 0367e3593..28f78a4fb 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -14,7 +14,8 @@ class Settings::ProfilesController < ApplicationController def show; end def update - if @account.update(account_params) + if UpdateAccountService.new.call(@account, account_params) + ActivityPub::UpdateDistributionWorker.perform_async(@account.id) redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg') else render :show |