Merge branch 'develop' into bugfix/hidden-poll-results-light-theme

This commit is contained in:
Dank Gabs 2019-07-16 16:54:41 -04:00
commit e3e98084e7
11 changed files with 95 additions and 15 deletions

View File

@ -2,7 +2,7 @@
module Admin module Admin
class AccountsController < BaseController class AccountsController < BaseController
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject, :verify, :unverify, :add_donor_badge, :remove_donor_badge, :add_investor_badge, :remove_investor_badge] before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject, :verify, :unverify, :add_donor_badge, :remove_donor_badge, :add_investor_badge, :remove_investor_badge, :edit_pro, :save_pro]
before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload] before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
before_action :require_local_account!, only: [:enable, :memorialize, :approve, :reject] before_action :require_local_account!, only: [:enable, :memorialize, :approve, :reject]
@ -162,6 +162,17 @@ module Admin
redirect_to admin_account_path(@account.id) redirect_to admin_account_path(@account.id)
end end
def edit_pro
authorize @account, :edit_pro?
end
def save_pro
authorize @account, :edit_pro?
@account.update!(pro_params)
redirect_to edit_pro_admin_account_path(@account.id)
end
private private
def set_account def set_account
@ -196,5 +207,9 @@ module Admin
:staff :staff
) )
end end
def pro_params
params.require(:account).permit(:is_pro, :pro_expires_at)
end
end end
end end

View File

@ -1,14 +1,17 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'gabsocial/components/icon'; import Icon from 'gabsocial/components/icon';
import { shortNumberFormat } from 'gabsocial/utils/numbers';
const formatNumber = num => num > 40 ? '40+' : num; const IconWithBadge = ({ id, count, className }) => {
if (count < 1) return null;
const IconWithBadge = ({ id, count, className }) => ( return (
<i className='icon-with-badge'> <i className='icon-with-badge'>
{count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>} {count > 0 && <i className='icon-with-badge__badge'>{shortNumberFormat(count)}</i>}
</i> </i>
); )
};
IconWithBadge.propTypes = { IconWithBadge.propTypes = {
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,

View File

@ -179,7 +179,11 @@ class Status extends ImmutablePureComponent {
} }
const { status } = this.props; const { status } = this.props;
this.context.router.history.push(`/${status.getIn(['account', 'acct'])}/posts/${status.getIn(['reblog', 'id'], status.get('id'))}`);
const isReblog = !!status.getIn(['reblog', 'id']);
const originalPosterUsername = isReblog ? status.getIn(['reblog', 'account', 'acct']) : status.getIn(['account', 'acct']);
this.context.router.history.push(`/${originalPosterUsername}/posts/${status.getIn(['reblog', 'id'], status.get('id'))}`);
} }
} }

View File

@ -4,16 +4,28 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import LoadingIndicator from '../../components/loading_indicator'; import LoadingIndicator from '../../components/loading_indicator';
import MissingIndicator from '../../components/missing_indicator';
import { fetchReblogs } from '../../actions/interactions'; import { fetchReblogs } from '../../actions/interactions';
import { fetchStatus } from '../../actions/statuses';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import AccountContainer from '../../containers/account_container'; import AccountContainer from '../../containers/account_container';
import Column from '../ui/components/column'; import Column from '../ui/components/column';
import ColumnBackButton from '../../components/column_back_button'; import ColumnBackButton from '../../components/column_back_button';
import ScrollableList from '../../components/scrollable_list'; import ScrollableList from '../../components/scrollable_list';
import { makeGetStatus } from '../../selectors';
const mapStateToProps = (state, props) => ({ const mapStateToProps = (state, props) => {
accountIds: state.getIn(['user_lists', 'reblogged_by', props.params.statusId]), const getStatus = makeGetStatus();
}); const status = getStatus(state, {
id: props.params.statusId,
username: props.params.username
});
return {
status,
accountIds: state.getIn(['user_lists', 'reblogged_by', props.params.statusId]),
}
};
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
class Reblogs extends ImmutablePureComponent { class Reblogs extends ImmutablePureComponent {
@ -22,20 +34,23 @@ class Reblogs extends ImmutablePureComponent {
params: PropTypes.object.isRequired, params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
accountIds: ImmutablePropTypes.list, accountIds: ImmutablePropTypes.list,
status: ImmutablePropTypes.map,
}; };
componentWillMount () { componentWillMount () {
this.props.dispatch(fetchReblogs(this.props.params.statusId)); this.props.dispatch(fetchReblogs(this.props.params.statusId));
this.props.dispatch(fetchStatus(this.props.params.statusId));
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
this.props.dispatch(fetchReblogs(nextProps.params.statusId)); this.props.dispatch(fetchReblogs(nextProps.params.statusId));
this.props.dispatch(fetchStatus(nextProps.params.statusId));
} }
} }
render () { render () {
const { accountIds } = this.props; const { accountIds, status } = this.props;
if (!accountIds) { if (!accountIds) {
return ( return (
@ -45,6 +60,14 @@ class Reblogs extends ImmutablePureComponent {
); );
} }
if (!status) {
return (
<Column>
<MissingIndicator />
</Column>
);
}
const emptyMessage = <FormattedMessage id='status.reblogs.empty' defaultMessage='No one has reposted this gab yet. When someone does, they will show up here.' />; const emptyMessage = <FormattedMessage id='status.reblogs.empty' defaultMessage='No one has reposted this gab yet. When someone does, they will show up here.' />;
return ( return (

View File

@ -63,7 +63,11 @@ const makeMapStateToProps = () => {
const getStatus = makeGetStatus(); const getStatus = makeGetStatus();
const mapStateToProps = (state, props) => { const mapStateToProps = (state, props) => {
const status = getStatus(state, { id: props.params.statusId }); const status = getStatus(state, {
id: props.params.statusId,
username: props.params.username
});
let ancestorsIds = Immutable.List(); let ancestorsIds = Immutable.List();
let descendantsIds = Immutable.List(); let descendantsIds = Immutable.List();

View File

@ -70,14 +70,21 @@ export const makeGetStatus = () => {
(state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]), (state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]), (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]), (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
(state, { username }) => username,
getFilters, getFilters,
], ],
(statusBase, statusReblog, accountBase, accountReblog, filters) => { (statusBase, statusReblog, accountBase, accountReblog, username, filters) => {
if (!statusBase) { if (!statusBase) {
return null; return null;
} }
const accountUsername = accountBase.get('acct');
//Must be owner of status if username exists
if (accountUsername !== username && username !== undefined) {
return null;
}
if (statusReblog) { if (statusReblog) {
statusReblog = statusReblog.set('account', accountReblog); statusReblog = statusReblog.set('account', accountReblog);
} else { } else {

View File

@ -61,6 +61,10 @@ class AccountPolicy < ApplicationPolicy
staff? staff?
end end
def edit_pro?
staff?
end
def update_badges? def update_badges?
staff? staff?
end end

View File

@ -0,0 +1,7 @@
.fields-row
.fields-row__column.fields-row__column-6.fields-group
%label{for: "is_pro"}
PRO
= f.check_box :is_pro, wrapper: :with_label, hint: false, id: "is_pro"
.fields-row__column.fields-row__column-6.fields-group
= f.input :pro_expires_at, as: :string, wrapper: :with_label, hint: false

View File

@ -0,0 +1,8 @@
- content_for :page_title do
= 'Edit PRO status of @' + @account.acct
= simple_form_for @account, url: save_pro_admin_account_path(@account.id), method: :put do |f|
= render 'edit_pro_fields', f: f
.actions
= f.button :button, t('generic.save_changes'), type: :submit

View File

@ -134,6 +134,9 @@
- if @account.is_pro? - if @account.is_pro?
=fa_icon 'check' =fa_icon 'check'
%time.formatted{ datetime: @account.pro_expires_at.iso8601, title: l(@account.pro_expires_at) }= l @account.pro_expires_at %time.formatted{ datetime: @account.pro_expires_at.iso8601, title: l(@account.pro_expires_at) }= l @account.pro_expires_at
%td
- if @account.local?
= table_link_to '', t('admin.accounts.edit_pro'), edit_pro_admin_account_path(@account.id), class: 'button' if can?(:verify, @account)
%tr %tr
%th= t('admin.accounts.is_verified') %th= t('admin.accounts.is_verified')

View File

@ -201,6 +201,8 @@ Rails.application.routes.draw do
post :remove_donor_badge post :remove_donor_badge
post :add_investor_badge post :add_investor_badge
post :remove_investor_badge post :remove_investor_badge
get :edit_pro
put :save_pro
end end
resource :change_email, only: [:show, :update] resource :change_email, only: [:show, :update]