Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release-0.35'
Browse files Browse the repository at this point in the history
Release v0.35: Premium accounts

**Enhancements:**
- Add support for premium accounts & make private projects a premium
  feature. Free users can only create public projects, while premium
  users can choose between public and private when creating the project.
- Improve the notification icon by replacing the old world icon with a
  bell icon. This should help more clearly identify it as a notification
  icon.
  ([#318](https://github.com/OpenlyOne/openly/issues/318))
- Improve placement of profile actions: Demote the edit profile button
  from floating action button to flat button. Add a button to create a
  new project as the primary action on the profile page. This should
  help solve the confusion of users who think they can create a project
  by clicking the button that actually takes them to the edit profile
  page
  ([#292](https://github.com/OpenlyOne/openly/issues/292))

**Fixes:**
- Do not show file diffs when plain text between two document version is
  the same
  ([#240](https://github.com/OpenlyOne/openly/issues/240))
  • Loading branch information
FinnWoelm committed Feb 12, 2019
2 parents bcbad61 + 228c31f commit 0cffa90
Show file tree
Hide file tree
Showing 44 changed files with 1,062 additions and 253 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# CHANGELOG

## v0.35 (Feb 13, 2019)

**Enhancements:**
- Add support for premium accounts & make private projects a premium feature.
Free users can only create public projects, while premium users can choose
between public and private when creating the project.
- Improve the notification icon by replacing the old world icon with a bell
icon. This should help more clearly identify it as a notification icon.
([#318](https://github.com/OpenlyOne/openly/issues/318))
- Improve placement of profile actions: Demote the edit profile button from
floating action button to flat button. Add a button to create a new project
as the primary action on the profile page. This should help solve the
confusion of users who think they can create a project by clicking the button
that actually takes them to the edit profile page
([#292](https://github.com/OpenlyOne/openly/issues/292))

**Fixes:**
- Do not show file diffs when plain text between two document version is the
same
([#240](https://github.com/OpenlyOne/openly/issues/240))


## v0.34 (Feb 10, 2019)

**Enhancements:**
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/controllers/profiles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $picture-size-small: 100px;
}
}

.social-links {
.edit-section {
a {
display: inline-block;
margin-left: 16px;
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/controllers/revisions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,16 @@
.links {
margin-top: 5px;
}

.help-icon-wrapper {
cursor: help;
margin-left: 5px;
position: relative;
top: -2px;
}

.help-icon {
vertical-align: middle;
}
}
}
6 changes: 6 additions & 0 deletions app/assets/stylesheets/shared/chips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@
border-top-left-radius: inherit;
border-top-right-radius: 0;
}

// align chip with text
&.inline {
margin: 0 5px;
vertical-align: top;
}
}
4 changes: 4 additions & 0 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def show
.includes(:owner, :master_branch)
.order(captured_at: :desc)
@user_can_edit_profile = can?(:edit, @profile)
# TODO: Add ability that checks whether the user can create a project
# within the current profile scope, which could be on organization
# that the user has access to.
@user_can_create_project = @user_can_edit_profile
end

def edit; end
Expand Down
33 changes: 29 additions & 4 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ class ProjectsController < ApplicationController

before_action :authenticate_account!, except: :show
before_action :build_project, only: %i[new create]
before_action :assign_create_params_to_project, only: %i[create]
before_action :set_project, only: %i[show edit update destroy]
before_action :authorize_action, only: %i[edit update destroy]
before_action :authorize_action, only: %i[create edit update destroy]
before_action :authorize_project_access, only: :show
before_action :set_user_can_create_private_projects, only: %i[new create]


def new; end

def create
if @project.update(project_params)
if @project.save
redirect_with_success_to(
new_profile_project_setup_path(@project.owner, @project)
)
Expand Down Expand Up @@ -62,13 +65,22 @@ def destroy
private

rescue_from CanCan::AccessDenied do |exception|
can_can_access_denied(exception)
case action_name.to_sym
when :create
raise StandardError, 'Unauthorized to create private project'
else
can_can_access_denied(exception)
end
end

def authorize_action
authorize! params[:action].to_sym, @project
end

def assign_create_params_to_project
@project.assign_attributes(project_create_params)
end

def build_project
@project = current_user.projects.build
end
Expand All @@ -81,11 +93,24 @@ def profile_slug
params[:slug]
end

def project_create_params
params
.require(:project)
.permit(:title, :slug, :tag_list, :description, :is_public)
end

def project_params
params.require(:project).permit(:title, :slug, :tag_list, :description)
params
.require(:project)
.permit(:title, :slug, :tag_list, :description)
end

def project_overview_path
profile_project_overview_path(@project.owner, @project)
end

def set_user_can_create_private_projects
@user_can_create_private_projects =
current_user.can_create_private_projects?
end
end
6 changes: 5 additions & 1 deletion app/dashboards/account_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AccountDashboard < Administrate::BaseDashboard
email: Field::String,
password: Field::Password,
password_confirmation: Field::Password,
is_premium: Field::Boolean,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze
Expand All @@ -28,6 +29,7 @@ class AccountDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = %i[
id
email
is_premium
user
].freeze

Expand All @@ -36,6 +38,7 @@ class AccountDashboard < Administrate::BaseDashboard
SHOW_PAGE_ATTRIBUTES = %i[
id
email
is_premium
user
created_at
updated_at
Expand All @@ -48,13 +51,14 @@ class AccountDashboard < Administrate::BaseDashboard
email
password
password_confirmation
is_premium
user
].freeze

# Overwrite this method to customize how accounts are displayed
# across all pages of the admin dashboard.
#
def display_resource(account)
account.email
account.premium? ? "#{account.email} (Premium)" : account.email
end
end
9 changes: 0 additions & 9 deletions app/dashboards/profiles/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class UserDashboard < Administrate::BaseDashboard
banner: PaperclipField,
about: Field::Text,
location: Field::String,
link_to_website: Field::String,
link_to_facebook: Field::String,
link_to_twitter: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze
Expand Down Expand Up @@ -51,9 +48,6 @@ class UserDashboard < Administrate::BaseDashboard
banner
about
location
link_to_website
link_to_facebook
link_to_twitter
].freeze

# FORM_ATTRIBUTES
Expand All @@ -67,9 +61,6 @@ class UserDashboard < Administrate::BaseDashboard
banner
about
location
link_to_website
link_to_facebook
link_to_twitter
].freeze

# Overwrite this method to customize how users are displayed
Expand Down
12 changes: 12 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Ability
include CanCan::Ability

# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def initialize(user)
# Users can view public projects and private projects they are collaborators
# of
Expand All @@ -23,6 +24,16 @@ def initialize(user)
can?(:edit, project) || project.collaborators.exists?(user.id)
end

can :create, Project do |project|
# Users can only create projects for profiles they can manage
can?(:manage, project.owner) &&
( # All users can create non-private projects.
!project.private? ||
# Premium users can create private projects.
(project.private? && user.premium_account?)
)
end

# Users can edit the projects of profiles that they can manage
can %i[edit update destroy], Project do |project|
can? :manage, project.owner
Expand Down Expand Up @@ -91,4 +102,5 @@ def initialize(user)
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
end
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
end
5 changes: 5 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Account < ApplicationRecord
validates :user, presence: true, on: :create
devise :validatable

# Return true if the account has a premium membership
def premium?
is_premium
end

# Monkey patch activity_notification's notify_to, so that it returns an
# instance of Notification (instead of ActivityNotification::Notification)
def notify_to(notifying_object, options = {})
Expand Down
10 changes: 10 additions & 0 deletions app/models/profiles/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ class User < Base

# Delegations
delegate :admin?, to: :account

def premium_account?
account.premium?
end

def can_create_private_projects?
Ability
.new(self)
.can?(:create, Project.new(is_public: false, owner: self))
end
end
end
9 changes: 7 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class Project < ApplicationRecord
# Title & slug must be present
validates :title, presence: true, length: { maximum: 50 }
validates :slug, presence: true
validates :is_public,
inclusion: {
in: [true, false],
message: 'must be public or private'
}
# Conduct validations only if slug is present
with_options if: :slug? do
validates :slug, length: { maximum: 50 }
Expand Down Expand Up @@ -157,11 +162,11 @@ def contributions_enabled?
end

def private?
!public?
is_public == false
end

def public?
is_public
is_public == true
end

# Return true if the setup process for this project has not started
Expand Down
14 changes: 11 additions & 3 deletions app/views/application/_navbar_signed_in.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ li
- if notification_count.nonzero?
span.badge.unread.black.white-text.z-depth-1.right
= notification_count
i.material-icons
svg style="width:24px;height:24px" viewBox="0 0 24 24"
path fill="currentColor" d="M17.9,17.39C17.64,16.59 16.89,16 16,16H15V13A1,1 0 0,0 14,12H8V10H10A1,1 0 0,0 11,9V7H13A2,2 0 0,0 15,5V4.59C17.93,5.77 20,8.64 20,12C20,14.08 19.2,15.97 17.9,17.39M11,19.93C7.05,19.44 4,16.08 4,12C4,11.38 4.08,10.78 4.21,10.21L9,15V16A2,2 0 0,0 11,18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"

/ ringing bell
i.material-icons
svg style="width:24px;height:24px" viewBox="0 0 24 24"
path fill="currentColor" d="M21,19V20H3V19L5,17V11C5,7.9 7.03,5.17 10,4.29C10,4.19 10,4.1 10,4A2,2 0 0,1 12,2A2,2 0 0,1 14,4C14,4.1 14,4.19 14,4.29C16.97,5.17 19,7.9 19,11V17L21,19M14,21A2,2 0 0,1 12,23A2,2 0 0,1 10,21M19.75,3.19L18.33,4.61C20.04,6.3 21,8.6 21,11H23C23,8.07 21.84,5.25 19.75,3.19M1,11H3C3,8.6 3.96,6.3 5.67,4.61L4.25,3.19C2.16,5.25 1,8.07 1,11Z"

- else
/ non-ringing bell
i.material-icons
svg style="width:24px;height:24px" viewBox="0 0 24 24"
path fill="currentColor" d="M21,19V20H3V19L5,17V11C5,7.9 7.03,5.17 10,4.29C10,4.19 10,4.1 10,4A2,2 0 0,1 12,2A2,2 0 0,1 14,4C14,4.1 14,4.19 14,4.29C16.97,5.17 19,7.9 19,11V17L21,19M14,21A2,2 0 0,1 12,23A2,2 0 0,1 10,21"


li
Expand Down
17 changes: 17 additions & 0 deletions app/views/contributions/reviews/_content_change.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.content-change

/ If all fragments are retained, do not show a (useless) diff. Show message
/ instead.
- if content_change.fragments.all?(&:retain?)
span.fragment
| Text will not change
span.help-icon-wrapper.gray-text.text-lighten-1 title='The text content of this file will not change. The file shows up as modified because other elements - such as styles or images - will be modified.'
svg.help-icon style="width:24px;height:24px;" viewBox="0 0 24 24"
path fill="currentColor" d="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"


/ Okay, we have an actual diff. Let's display it.
- else
= render partial: 'revisions/content_change_fragment',
collection: content_change.fragments,
locals: { truncate_content: true }
6 changes: 2 additions & 4 deletions app/views/contributions/reviews/_file_change.slim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,5 @@ div.file[class=file_change.symbolic_mime_type
link_options: link_options }

- if file_change.modification? && file_change.content_change.present?
.content-change
= render partial: 'revisions/content_change_fragment',
collection: file_change.content_change.fragments,
locals: { truncate_content: true }
= render partial: 'contributions/reviews/content_change',
object: file_change.content_change
Loading

0 comments on commit 0cffa90

Please sign in to comment.