Skip to content

Commit

Permalink
Reapply "Merge branch 'glitch-soc:main' into main"
Browse files Browse the repository at this point in the history
This reverts commit f4c400d.
  • Loading branch information
Ember-ruby committed Jan 22, 2024
1 parent 5b0f546 commit 7f63ff2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
2 changes: 2 additions & 0 deletions app/javascript/flavours/glitch/components/account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Account extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
hidden: PropTypes.bool,
minimal: PropTypes.bool,
actionIcon: PropTypes.string,
actionTitle: PropTypes.string,
defaultAction: PropTypes.string,
withBio: PropTypes.bool,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';

import AttachmentList from 'flavours/glitch/components/attachment_list';
import { WithOptionalRouterPropTypes, withOptionalRouter } from 'flavours/glitch/utils/react_router';

import { Avatar } from '../../../components/avatar';
import { DisplayName } from '../../../components/display_name';
import { IconButton } from '../../../components/icon_button';
import AccountContainer from '../../../containers/account_container';

const messages = defineMessages({
cancel: { id: 'reply_indicator.cancel', defaultMessage: 'Cancel' },
Expand All @@ -18,14 +20,19 @@ class ReplyIndicator extends ImmutablePureComponent {

static propTypes = {
status: ImmutablePropTypes.map,
onCancel: PropTypes.func,
onCancel: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
...WithOptionalRouterPropTypes,
};

handleClick = () => {
const { onCancel } = this.props;
if (onCancel) {
onCancel();
this.props.onCancel();
};

handleAccountClick = (e) => {
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault();
this.props.history?.push(`/@${this.props.status.getIn(['account', 'acct'])}`);
}
};

Expand All @@ -38,19 +45,15 @@ class ReplyIndicator extends ImmutablePureComponent {

const content = { __html: status.get('contentHtml') };

const account = status.get('account');

return (
<div className='reply-indicator'>
<div className='reply-indicator__header'>
<div className='reply-indicator__cancel'><IconButton title={intl.formatMessage(messages.cancel)} icon='times' onClick={this.handleClick} inverted /></div>

{account && (
<AccountContainer
id={account}
small
/>
)}
<a href={status.getIn(['account', 'url'])} onClick={this.handleAccountClick} className='reply-indicator__display-name' target='_blank' rel='noopener noreferrer'>
<div className='reply-indicator__display-avatar'><Avatar account={status.get('account')} size={24} /></div>
<DisplayName account={status.get('account')} inline />
</a>
</div>

<div className='reply-indicator__content translate' dangerouslySetInnerHTML={content} />
Expand All @@ -67,4 +70,4 @@ class ReplyIndicator extends ImmutablePureComponent {

}

export default injectIntl(ReplyIndicator);
export default withOptionalRouter(injectIntl(ReplyIndicator));
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { connect } from 'react-redux';

import { cancelReplyCompose } from '../../../actions/compose';
import { makeGetStatus } from '../../../selectors';
import ReplyIndicator from '../components/reply_indicator';

const makeMapStateToProps = () => {
const getStatus = makeGetStatus();

const mapStateToProps = state => {
let statusId = state.getIn(['compose', 'id'], null);
let editing = true;
Expand All @@ -14,7 +17,7 @@ const makeMapStateToProps = () => {
}

return {
status: state.getIn(['statuses', statusId]),
status: getStatus(state, { id: statusId }),
editing,
};
};
Expand Down
23 changes: 19 additions & 4 deletions app/javascript/flavours/glitch/styles/components/compose_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,32 @@
.reply-indicator__header {
margin-bottom: 5px;
overflow: hidden;

& > .account.small {
color: $inverted-text-color;
}
}

.reply-indicator__cancel {
float: right;
line-height: 24px;
}

.reply-indicator__display-name {
color: $inverted-text-color;
display: block;
max-width: 100%;
line-height: 24px;
overflow: hidden;
text-decoration: none;

& > .display-name {
line-height: unset;
height: unset;
}
}

.reply-indicator__display-avatar {
float: left;
margin-inline-end: 5px;
}

.reply-indicator__content {
position: relative;
font-size: 14px;
Expand Down
18 changes: 9 additions & 9 deletions app/javascript/packs/public.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client';
import { IntlMessageFormat } from 'intl-messageformat';
import { defineMessages } from 'react-intl';

import delegate from '@rails/ujs';
import Rails from '@rails/ujs';
import axios from 'axios';
import { throttle } from 'lodash';

Expand Down Expand Up @@ -129,7 +129,7 @@ function loaded() {
});
}

delegate(document, '#user_account_attributes_username', 'input', throttle(({ target }) => {
Rails.delegate(document, '#user_account_attributes_username', 'input', throttle(({ target }) => {
if (target.value && target.value.length > 0) {
axios.get('/api/v1/accounts/lookup', { params: { acct: target.value } }).then(() => {
target.setCustomValidity(formatMessage(messages.usernameTaken));
Expand All @@ -141,7 +141,7 @@ function loaded() {
}
}, 500, { leading: false, trailing: true }));

delegate(document, '#user_password,#user_password_confirmation', 'input', () => {
Rails.delegate(document, '#user_password,#user_password_confirmation', 'input', () => {
const password = document.getElementById('user_password');
const confirmation = document.getElementById('user_password_confirmation');
if (!confirmation) return;
Expand All @@ -155,7 +155,7 @@ function loaded() {
}
});

delegate(document, '.status__content__spoiler-link', 'click', function() {
Rails.delegate(document, '.status__content__spoiler-link', 'click', function() {
const statusEl = this.parentNode.parentNode;

if (statusEl.dataset.spoiler === 'expanded') {
Expand Down Expand Up @@ -192,23 +192,23 @@ const toggleSidebar = () => {
sidebar.classList.toggle('visible');
};

delegate(document, '.sidebar__toggle__icon', 'click', () => {
Rails.delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar();
});

delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
Rails.delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
toggleSidebar();
}
});

delegate(document, '.custom-emoji', 'mouseover', ({ target }) => target.src = target.getAttribute('data-original'));
delegate(document, '.custom-emoji', 'mouseout', ({ target }) => target.src = target.getAttribute('data-static'));
Rails.delegate(document, '.custom-emoji', 'mouseover', ({ target }) => target.src = target.getAttribute('data-original'));
Rails.delegate(document, '.custom-emoji', 'mouseout', ({ target }) => target.src = target.getAttribute('data-static'));

// Empty the honeypot fields in JS in case something like an extension
// automatically filled them.
delegate(document, '#registration_new_user,#new_user', 'submit', () => {
Rails.delegate(document, '#registration_new_user,#new_user', 'submit', () => {
['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => {
const field = document.getElementById(id);
if (field) {
Expand Down
11 changes: 11 additions & 0 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
assets_host = policy.assets_host
media_hosts = policy.media_hosts

base_host = Rails.configuration.x.web_domain

assets_host = Rails.configuration.action_controller.asset_host
assets_host ||= host_to_url(base_host)

media_host = host_to_url(ENV['S3_ALIAS_HOST'])

Check failure on line 20 in config/initializers/content_security_policy.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/FetchEnvVar: Use ENV.fetch('S3_ALIAS_HOST') or ENV.fetch('S3_ALIAS_HOST', nil) instead of ENV['S3_ALIAS_HOST']. (https://rubystyle.guide/#hash-fetch-defaults)
media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST'])

Check failure on line 21 in config/initializers/content_security_policy.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/FetchEnvVar: Use ENV.fetch('S3_CLOUDFRONT_HOST') or ENV.fetch('S3_CLOUDFRONT_HOST', nil) instead of ENV['S3_CLOUDFRONT_HOST']. (https://rubystyle.guide/#hash-fetch-defaults)
media_host ||= host_to_url(ENV['AZURE_ALIAS_HOST'])

Check failure on line 22 in config/initializers/content_security_policy.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/FetchEnvVar: Use ENV.fetch('AZURE_ALIAS_HOST') or ENV.fetch('AZURE_ALIAS_HOST', nil) instead of ENV['AZURE_ALIAS_HOST']. (https://rubystyle.guide/#hash-fetch-defaults)
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'

Check failure on line 23 in config/initializers/content_security_policy.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/FetchEnvVar: Use ENV.fetch('S3_HOSTNAME') or ENV.fetch('S3_HOSTNAME', nil) instead of ENV['S3_HOSTNAME']. (https://rubystyle.guide/#hash-fetch-defaults)
media_host ||= assets_host

Check warning on line 24 in config/initializers/content_security_policy.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Lint/UselessAssignment: Useless assignment to variable - media_host. (https://rubystyle.guide#underscore-unused-vars)

def sso_host
return unless ENV['ONE_CLICK_SSO_LOGIN'] == 'true'
return unless ENV['OMNIAUTH_ONLY'] == 'true'
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/content_security_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"default-src 'none'",
"frame-ancestors 'none'",
"font-src 'self' https://cb6e6126.ngrok.io",
"img-src 'self' data: blob: https://cb6e6126.ngrok.io",
"img-src 'self' data: blob: https://cb6e6126.ngrok.io https://cb6e6126.ngrok.io",
"style-src 'self' https://cb6e6126.ngrok.io 'nonce-ZbA+JmE7+bK8F5qvADZHuQ=='",
"media-src 'self' data: https://cb6e6126.ngrok.io",
"media-src 'self' data: https://cb6e6126.ngrok.io https://cb6e6126.ngrok.io",
"frame-src 'self' https:",
"manifest-src 'self' https://cb6e6126.ngrok.io",
"form-action 'self'",
Expand Down

0 comments on commit 7f63ff2

Please sign in to comment.