Skip to content

Commit

Permalink
Enterprise Edition support tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
wielinde authored and oliverguenther committed Jan 17, 2017
1 parent 0e1f4ed commit 49f12b3
Show file tree
Hide file tree
Showing 35 changed files with 1,104 additions and 19 deletions.
24 changes: 24 additions & 0 deletions .openproject-token.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN PUBLIC KEY-----
MIIEFjANBgkqhkiG9w0BAQEFAAOCBAMAMIID/gKCA/UAquIZchoog2ffcr9J2KSl
mlum6sN3smTVNsp9JGd1q4fr/kUFGch6q1cFEX3x5BGDXx7wPPI4ppKzeQHaxWmx
wxqs3eevcTFUEF9A2MPX7p5Ia0TbH4d7e7D9YMWvDXoQLggrxMFdUHY3ppUnBPgB
+EJG1Pv0FlBAdxYX0em7kLwhcp9PBP/zXso/qkkKK/pncyKizOLC3zv3E0ixcQ7o
Nq0aolTJFMHcqEquKaQN1jicDdzU6ks+YKh7kByZvVChe/InlroVXKrUa34hAZDM
acEkURJma3meN0IyPFA7fHRe1AhiNYF2MatNKysPrbOffYLOjamlaqmHTeJAec6e
vMHd+LlIz4xXivR0lY2wDawqp0waSLJaW8lZetOf0iwbqQkzZhz4sWDZopyGiqAU
v9/zS4OjUBr7JQbVcV3LIkzGWwNysSvTMrlvzCesYVsCwpLjP6gFxdclYJuTwEeL
o+T+AgoNyuj6ixhwHTJxIVhuBpebX44/YTYyUGMgItekDCH2Dxvtv2DaCL7YIqNG
ibvCyzCyLak7Tz97CMvCUf1EIRVfolbGpphi2Zzpoeqhfheh+0LQ3gmMBJpuLnJU
VXEtrOPunTkOrdUqL5rD/+mfd8yufsJ16Uk5j7gNUcIJsCcGWZ3Nhfidi3tvmJPF
H8HgNZ6W6smj9k7+TdZbRsH1LZp1LL/stLch3ffFHHcJye7d2t75uKiOoz1/1JMY
fl/wfaEaKvTGBKr/NFKcVDSBXHgx6VMA3oWV2AyLnTaY98XVPY1zzbyNKlNQkSaD
p/VCl334+YMwR9/5aJYJg58lljw6aBu+cozNkydKjCmqEpZNdR1tFusAY7jd/M2G
yXPBTdUJD6GrLx0Hot/wImJ30gOMgpeoetNUfM9/FimySLy65DRzCtLm1hthAlWM
Is5vFwMmFFSb3ozTsnkj9W16jHk9HdodKJfezzcPqu3TW2EMMNbbtXa3OPaHkht2
huYJGnGu0hNhAj+x+KCxkpLveS0Ajw322qmtAqnwJLvfwShnz//cptNX5kXtrNGy
+o6I4jHibIATfaMKMt8gHmCZ381zAwrAOU7c0FQna+IkU8dgZDx7T+Xo1Q/GXuaO
1b2aT6geT60A3VgF+OBnoHe5Ext7vfNL9v0wcN5NLR5KgjexwEhcBcA2FauCTrVt
FUNgir+5XALd/wBlvxkvPKTJnQld/aK7xF0ui3c3/ryPX5cKzpfm9APK/hOFzkJ7
ieARHqrQGqOYdClIUJIH0b/92dFq49Eqn1cKpztVzsU9xzdI/4w5JUSw/kbguVf7
Yd0Rdc9KF/9WMwjzrWSti4meNBUO6/18cAognx0Pf5qsrSzOewIDAQAB
-----END PUBLIC KEY-----
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ gem 'nokogiri', '~> 1.6.8'
gem 'fog-aws'
gem 'carrierwave', git: 'https://github.com/carrierwaveuploader/carrierwave', branch: 'master'

gem 'openproject-token', '~> 1.0.0'

group :test do
gem 'rack-test', '~> 0.6.3'
gem 'shoulda-context', '~> 1.2'
Expand Down Expand Up @@ -261,7 +263,7 @@ platforms :jruby do
end

group :opf_plugins do
gem 'openproject-translations', git: 'https://github.com/opf/openproject-translations.git', branch: 'release/6.1'
gem 'openproject-translations', git: 'https://github.com/opf/openproject-translations.git', branch: 'dev'
end

# TODO: Make this group :optional when bundler v10.x
Expand Down
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ GIT

GIT
remote: https://github.com/opf/openproject-translations.git
revision: 1e8c4e52119f0ea690bf7d015798ae65b1af0f7a
branch: release/6.1
revision: bbc216af7f0133fd191fbe7ea121a2c962a8491f
branch: dev
specs:
openproject-translations (6.1.4)
openproject-translations (6.2.0)
crowdin-api (~> 0.4.1)
mixlib-shellout (~> 2.1.0)
rails (~> 5.0.0)
Expand Down Expand Up @@ -361,6 +361,8 @@ GEM
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
oj (2.17.4)
openproject-token (1.0.0)
activemodel (~> 5.0)
parallel (1.9.0)
parallel_tests (2.4.1)
parallel
Expand Down Expand Up @@ -648,6 +650,7 @@ DEPENDENCIES
nokogiri (~> 1.6.8)
oj (~> 2.17.4)
omniauth!
openproject-token (~> 1.0.0)
openproject-translations!
parallel_tests (~> 2.4.1)
passenger
Expand Down
Binary file added app/assets/images/enterprise_edition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/content/_enterprise.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.upsale-notification
max-width: 560px
margin-bottom: 20px
padding-bottom: 20px

.widget-box--teaser-image
width: 30%
float: right
margin-top: -20px

.token-form textarea
font-family: "Lucida Console", Monaco, monospace
max-width: 560px
4 changes: 4 additions & 0 deletions app/assets/stylesheets/content/_ng_dialog.sass
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
// Required for close icon
position: relative

.ngdialog-body
margin-top: 2rem
min-height: 50px

.ngdialog-close
cursor: pointer
position: absolute
Expand Down
25 changes: 24 additions & 1 deletion app/assets/stylesheets/content/_widget_box.sass
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ $widget-box--enumeration-width: 20px
flex-direction: column

.widget-box--enumeration,
.widget-box--arrow-links
.widget-box--arrow-links,
.widget-box--feature-list
flex-grow: 2

.icon-context:before
Expand Down Expand Up @@ -125,6 +126,28 @@ $widget-box--enumeration-width: 20px
//necessary for correct alignment even with long texts
width: calc(100% - #{$widget-box--enumeration-width})

.widget-box--feature-list
list-style: none
margin: 0.5rem 0 1rem 0

&:last-child
margin-bottom: 0

li:before
@include icon-common
@extend .icon-notice
@extend .icon-notice:before
display: inline-block
font-size: 0.6rem
color: $alternative-color
width: $widget-box--enumeration-width


.widget-box--teaser-image
height: 100px
margin-left: auto
margin-right: auto

@include breakpoint(680px down)
.widget-boxes
&.-flex
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/default.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
@import content/links
@import content/action_menu_main
@import content/legacy_actions
@import content/enterprise
@import content/my_page
@import content/project_overview
@import content/news
Expand Down
4 changes: 3 additions & 1 deletion app/assets/stylesheets/specific/onboarding.sass
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
//++
// Align ngDialog's close button
.onboarding-modal .ngdialog-close
.onboarding-modal .ngdialog-close,
.ngdialog-theme-openproject .ngdialog-close
line-height: $header-height
color: $header-item-font-color

.onboarding--top-menu
display: flex
Expand Down
67 changes: 67 additions & 0 deletions app/controllers/enterprises_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#-- 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 token 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 token
# as published by the Free Software Foundation; either version 2
# of the token, 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 token for more details.
#
# You should have received a copy of the GNU General Public token
# 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.
#++
class EnterprisesController < ApplicationController
layout 'admin'
menu_item :enterprise

before_action :require_admin

def show
@current_token = EnterpriseToken.current
@token = @current_token || EnterpriseToken.new
end

def create
@token = EnterpriseToken.current || EnterpriseToken.new
@token.encoded_token = params[:enterprise_token][:encoded_token]

if @token.save
flash[:notice] = t(:notice_successful_update)
redirect_to action: :show
else
render action: :show
end
end

def destroy
token = EnterpriseToken.current
if token
token.destroy
flash[:notice] = t(:notice_successful_delete)
redirect_to action: :show
else
render_404
end
end

private

def default_breadcrumb
t(:label_enterprise)
end
end
107 changes: 107 additions & 0 deletions app/models/enterprise_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#-- 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.
#++
class EnterpriseToken < ActiveRecord::Base
class << self
def current
RequestStore.fetch(cache_key) do
set_current_token
end
end

def cache_key
RequestStore.fetch(:current_ee_token_updated_at) { EnterpriseToken.maximum(:updated_at) }
most_recent_update = (RequestStore[:current_ee_token_updated_at] || Time.now.utc).to_i
"/openproject/ee/#{most_recent_update}"
end

def clear_cache(key = cache_key)
Rails.cache.delete(key)
RequestStore.delete key
RequestStore.delete :current_ee_token_updated_at
end

def allows_to?(action)
Authorization::EnterpriseService.new(current).call(action).result
end

def show_banners
!current || current.expired?
end

def set_current_token
token = EnterpriseToken.order('created_at DESC').first

if token && token.token_object
token
end
end
end

validates_presence_of :encoded_token
validate :valid_token_object

before_save :unset_current_token
before_destroy :unset_current_token

delegate :will_expire?,
:expired?,
:subscriber,
:mail,
:issued_at,
:starts_at,
:expires_at,
:restrictions,
to: :token_object

def token_object
@token_object = load_token unless defined?(@token_object)
@token_object
end

def allows_to?(action)
Authorization::EnterpriseService.new(self).call(action).result
end

def unset_current_token
# Clear current cache
self.class.clear_cache
end

private

def load_token
OpenProject::Token.import(encoded_token)
rescue OpenProject::Token::ImportError => error
Rails.logger.error "Failed to load EE token: #{error}"
nil
end

def valid_token_object
errors.add(:encoded_token, :unreadable) unless token_object
end
end
2 changes: 1 addition & 1 deletion app/models/queries/relations/relation_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.model
Relation
end

def self.default_scope
def default_scope
Relation.all
end
end
Expand Down
Loading

0 comments on commit 49f12b3

Please sign in to comment.