commit
4867d4ccc8
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,59 @@ |
||||
module OAuth |
||||
module Applications |
||||
class RowCell < ::RowCell |
||||
include ::IconsHelper |
||||
include ::OAuthHelper |
||||
include ::OpenProject::ObjectLinking |
||||
|
||||
def application |
||||
model |
||||
end |
||||
|
||||
def name |
||||
link_to application.name, oauth_application_path(application) |
||||
end |
||||
|
||||
def owner |
||||
link_to application.owner.name, user_path(application.owner) |
||||
end |
||||
|
||||
def confidential |
||||
if application.confidential? |
||||
op_icon 'icon icon-checkmark' |
||||
end |
||||
end |
||||
|
||||
def redirect_uri |
||||
urls = application.redirect_uri.split("\n") |
||||
safe_join urls, '<br/>'.html_safe |
||||
end |
||||
|
||||
def client_credentials |
||||
if user_id = application.client_credentials_user_id |
||||
link_to_user User.find(user_id) |
||||
else |
||||
'-' |
||||
end |
||||
end |
||||
|
||||
def confidential |
||||
application.confidential |
||||
end |
||||
|
||||
def edit_link |
||||
link_to( |
||||
I18n.t(:button_edit), |
||||
edit_oauth_application_path(application), |
||||
class: "oauth-application--edit-link icon icon-edit" |
||||
) |
||||
end |
||||
|
||||
def button_links |
||||
[ |
||||
edit_link, |
||||
delete_link(oauth_application_path(application)) |
||||
] |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
require_dependency 'oauth/applications/row_cell' |
||||
|
||||
module OAuth |
||||
module Applications |
||||
class TableCell < ::TableCell |
||||
|
||||
|
||||
class << self |
||||
def row_class |
||||
::OAuth::Applications::RowCell |
||||
end |
||||
end |
||||
|
||||
def initial_sort |
||||
%i[id asc] |
||||
end |
||||
|
||||
def sortable? |
||||
false |
||||
end |
||||
|
||||
def columns |
||||
headers.map(&:first) |
||||
end |
||||
|
||||
def inline_create_link |
||||
link_to new_oauth_application_path, |
||||
aria: { label: t('oauth.application.new') }, |
||||
class: 'wp-inline-create--add-link', |
||||
title: t('oauth.application.new') do |
||||
op_icon('icon icon-add') |
||||
end |
||||
end |
||||
|
||||
def empty_row_message |
||||
I18n.t :no_results_title_text |
||||
end |
||||
|
||||
def headers |
||||
[ |
||||
['name', caption: ::Doorkeeper::Application.human_attribute_name(:name)], |
||||
['owner', caption: ::Doorkeeper::Application.human_attribute_name(:owner)], |
||||
['client_credentials', caption: I18n.t('oauth.client_credentials')], |
||||
['redirect_uri', caption: ::Doorkeeper::Application.human_attribute_name(:redirect_uri)], |
||||
['confidential', caption: ::Doorkeeper::Application.human_attribute_name(:confidential)], |
||||
] |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,63 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'model_contract' |
||||
|
||||
module Oauth |
||||
class ApplicationContract < ::ModelContract |
||||
def self.model |
||||
::Doorkeeper::Application |
||||
end |
||||
|
||||
def validate |
||||
validate_client_credential_user |
||||
|
||||
super |
||||
end |
||||
|
||||
attribute :name |
||||
attribute :redirect_uri |
||||
attribute :confidential |
||||
attribute :owner_id |
||||
attribute :owner_type |
||||
attribute :scopes |
||||
attribute :client_credentials_user_id |
||||
|
||||
private |
||||
|
||||
def validate_client_credential_user |
||||
return unless model.client_credentials_user_id.present? |
||||
|
||||
unless User.where(id: model.client_credentials_user_id).exists? |
||||
errors.add :client_credentials_user_id, :invalid |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'model_contract' |
||||
|
||||
module Projects |
||||
class BaseContract < ::ModelContract |
||||
def self.model |
||||
::Project |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'model_contract' |
||||
|
||||
module Projects |
||||
class DeleteContract < BaseContract |
||||
def validate |
||||
unless user.admin? |
||||
errors.add :base, :error_unauthorized |
||||
end |
||||
|
||||
super |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,118 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
|
||||
module OAuth |
||||
class ApplicationsController < ::ApplicationController |
||||
before_action :require_admin |
||||
before_action :new_app, only: %i[new create] |
||||
before_action :find_app, only: %i[edit update show destroy] |
||||
|
||||
layout 'admin' |
||||
menu_item :oauth_applications |
||||
|
||||
def index |
||||
@applications = ::Doorkeeper::Application.includes(:owner).all |
||||
end |
||||
|
||||
def new; end |
||||
def edit; end |
||||
|
||||
def show |
||||
@reveal_secret = flash[:reveal_secret] |
||||
flash.delete :reveal_secret |
||||
end |
||||
|
||||
def create |
||||
call = ::OAuth::PersistApplicationService.new(@application, user: current_user) |
||||
.call(permitted_params.oauth_application) |
||||
|
||||
if call.success? |
||||
flash[:notice] = t(:notice_successful_create) |
||||
flash[:_application_secret] = call.result.plaintext_secret |
||||
redirect_to action: :show, id: call.result.id |
||||
else |
||||
@errors = call.errors |
||||
flash[:error] = call.errors.full_messages.join('\n') |
||||
render action: :new |
||||
end |
||||
end |
||||
|
||||
def update |
||||
call = ::OAuth::PersistApplicationService.new(@application, user: current_user) |
||||
.call(permitted_params.oauth_application) |
||||
|
||||
if call.success? |
||||
flash[:notice] = t(:notice_successful_update) |
||||
redirect_to action: :index |
||||
else |
||||
@errors = call.errors |
||||
flash[:error] = call.errors.full_messages.join('\n') |
||||
render action: :edit |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
if @application.destroy |
||||
flash[:notice] = t(:notice_successful_delete) |
||||
else |
||||
flash[:error] = t(:error_can_not_delete_entry) |
||||
end |
||||
|
||||
redirect_to action: :index |
||||
end |
||||
|
||||
|
||||
protected |
||||
|
||||
def default_breadcrumb |
||||
if action_name == 'index' |
||||
t('oauth.application.plural') |
||||
else |
||||
ActionController::Base.helpers.link_to(t('oauth.application.plural'), oauth_applications_path) |
||||
end |
||||
end |
||||
|
||||
def show_local_breadcrumb |
||||
current_user.admin? |
||||
end |
||||
|
||||
private |
||||
|
||||
def new_app |
||||
@application = ::Doorkeeper::Application.new |
||||
end |
||||
|
||||
def find_app |
||||
@application = ::Doorkeeper::Application.find(params[:id]) |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,67 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
|
||||
module OAuth |
||||
class GrantsController < ::ApplicationController |
||||
before_action :require_login |
||||
|
||||
layout 'my' |
||||
menu_item :access_token |
||||
|
||||
def index |
||||
@applications = ::Doorkeeper::Application.authorized_for(current_user) |
||||
end |
||||
|
||||
def revoke_application |
||||
application = find_application |
||||
if application.nil? |
||||
render_404 |
||||
return |
||||
end |
||||
|
||||
::Doorkeeper::Application.revoke_tokens_and_grants_for( |
||||
application.id, |
||||
current_user |
||||
) |
||||
|
||||
flash[:notice] = I18n.t('oauth.grants.successful_application_revocation', application_name: application.name) |
||||
redirect_to controller: '/my', action: :access_token |
||||
end |
||||
|
||||
private |
||||
|
||||
def find_application |
||||
::Doorkeeper::Application |
||||
.where(id: params[:application_id]) |
||||
.select(:name, :id) |
||||
.take |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module StaticLinksHelper |
||||
|
||||
## |
||||
# Create a static link to the given key entry |
||||
def static_link_to(key) |
||||
item = OpenProject::Static::Links.links.fetch key |
||||
link_to t(item[:label]), item[:href], class: 'openproject--static-link' |
||||
end |
||||
end |
@ -0,0 +1,90 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class ProjectMailer < BaseMailer |
||||
|
||||
def delete_project_completed(project, user:) |
||||
open_project_headers Project: project.identifier, |
||||
Author: user.login |
||||
|
||||
message_id project, user |
||||
with_locale_for(user) do |
||||
@project = project |
||||
mail to: user.mail, subject: I18n.t('projects.delete.completed', name: project.name) |
||||
end |
||||
end |
||||
|
||||
def delete_project_failed(project, user:) |
||||
open_project_headers Project: project.identifier, |
||||
Author: user.login |
||||
|
||||
message_id project, user |
||||
with_locale_for(user) do |
||||
@project = project |
||||
|
||||
mail to: user.mail, subject: I18n.t('projects.delete.failed', name: project.name) |
||||
end |
||||
end |
||||
|
||||
def copy_project_failed(user, source_project, target_project_name, errors) |
||||
@source_project = source_project |
||||
@target_project_name = target_project_name |
||||
@errors = errors |
||||
|
||||
open_project_headers 'Source-Project' => source_project.identifier, |
||||
'Author' => user.login |
||||
|
||||
message_id project, user |
||||
|
||||
with_locale_for(user) do |
||||
subject = I18n.t('copy_project.failed', source_project_name: source_project.name) |
||||
|
||||
mail to: user.mail, subject: subject |
||||
end |
||||
end |
||||
|
||||
def copy_project_succeeded(user, source_project, target_project, errors) |
||||
@source_project = source_project |
||||
@target_project = target_project |
||||
@errors = errors |
||||
|
||||
open_project_headers 'Source-Project' => source_project.identifier, |
||||
'Target-Project' => target_project.identifier, |
||||
'Author' => user.login |
||||
|
||||
message_id target_project, user |
||||
|
||||
with_locale_for(user) do |
||||
subject = I18n.t('copy_project.succeeded', target_project_name: target_project.name) |
||||
|
||||
mail to: user.mail, subject: subject |
||||
end |
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue