forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserCustomCssController < ActionController::Base # rubocop:disable Rails/ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show | ||
render content_type: 'text/css' | ||
end | ||
|
||
private | ||
|
||
def user_custom_css | ||
current_user.custom_css_text | ||
end | ||
helper_method :user_custom_css | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,3 @@ | |
} | ||
|
||
<%- end %> | ||
<%- if user_custom_css? %> | ||
<%= raw user_custom_css %> | ||
|
||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= raw user_custom_css %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'User custom CSS' do | ||
let(:user) { Fabricate(:user) } | ||
let(:custom_css) { '* { display: none !important; }' } | ||
|
||
describe 'GET /user_custom.css' do | ||
context 'without sign in' do | ||
it 'returns 422' do | ||
get '/user_custom.css' | ||
|
||
expect(response).to have_http_status(401) | ||
end | ||
end | ||
|
||
context 'with sign in but custom css is not enabled' do | ||
before do | ||
user.update!(custom_css_text: custom_css) | ||
sign_in user | ||
end | ||
|
||
it 'returns custom css' do | ||
get '/user_custom.css' | ||
|
||
expect(response).to have_http_status(200) | ||
expect(response.content_type).to include 'text/css' | ||
expect(response.body.strip).to eq custom_css | ||
end | ||
end | ||
|
||
context 'with sign in and custom css is enabled' do | ||
before do | ||
user.update!(custom_css_text: custom_css, settings: { 'web.use_custom_css': true }) | ||
sign_in user | ||
end | ||
|
||
it 'returns custom css' do | ||
get '/user_custom.css' | ||
|
||
expect(response).to have_http_status(200) | ||
expect(response.content_type).to include 'text/css' | ||
expect(response.body.strip).to eq custom_css | ||
end | ||
end | ||
end | ||
end |