From 3fa8eb1bac13e535f01396211851c409ea914bf6 Mon Sep 17 00:00:00 2001 From: 2458773093 <2458773093@protonmail.com> Date: Thu, 1 Aug 2019 19:46:17 +0300 Subject: [PATCH] Added restriction to group policy. Create link hidden for non-pro. --- app/controllers/api/v1/groups_controller.rb | 2 ++ app/javascript/gabsocial/features/groups/index/index.js | 6 ++++-- app/policies/group_policy.rb | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index 330f337c..f59db12c 100644 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -33,6 +33,8 @@ class Api::V1::GroupsController < Api::BaseController end def create + authorize :group, :create? + @group = Group.create!(group_params.merge(account: current_account)) render json: @group, serializer: REST::GroupSerializer end diff --git a/app/javascript/gabsocial/features/groups/index/index.js b/app/javascript/gabsocial/features/groups/index/index.js index 4b488141..e40e957e 100644 --- a/app/javascript/gabsocial/features/groups/index/index.js +++ b/app/javascript/gabsocial/features/groups/index/index.js @@ -9,6 +9,7 @@ import { Link } from 'react-router-dom'; import classNames from 'classnames'; import GroupCard from './card'; import GroupCreate from '../create'; +import { me } from 'gabsocial/initial_state'; const messages = defineMessages({ heading: { id: 'column.groups', defaultMessage: 'Groups' }, @@ -20,6 +21,7 @@ const messages = defineMessages({ const mapStateToProps = (state, { activeTab }) => ({ groupIds: state.getIn(['group_lists', activeTab]), + account: state.getIn(['accounts', me]), }); export default @connect(mapStateToProps) @@ -46,11 +48,11 @@ class Groups extends ImmutablePureComponent { } renderHeader() { - const { intl, activeTab } = this.props; + const { intl, activeTab, account } = this.props; return (
-
{intl.formatMessage(messages.create)}
+ {account && account.get('is_pro') &&
{intl.formatMessage(messages.create)}
}
{intl.formatMessage(messages.heading)}
diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb index 76843abc..2737268d 100644 --- a/app/policies/group_policy.rb +++ b/app/policies/group_policy.rb @@ -5,6 +5,10 @@ class GroupPolicy < ApplicationPolicy true end + def create? + admin? or current_account.is_pro + end + def update? if admin? true