forked from increments/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'qiitadon' into qiitadon-v1.5.0
Conflicts: Gemfile.lock README.md app/controllers/admin/settings_controller.rb app/javascript/mastodon/features/ui/index.js app/javascript/mastodon/locales/en.json app/javascript/mastodon/locales/ja.json app/javascript/packs/public.js app/models/user.rb app/presenters/instance_presenter.rb app/views/about/_links.html.haml app/views/about/_registration.html.haml app/views/about/show.html.haml app/views/admin/settings/edit.html.haml app/views/api/v1/accounts/show.rabl app/views/auth/registrations/edit.html.haml app/views/home/initial_state.json.rabl config/locales/en.yml config/locales/ja.yml config/routes.rb public/android-chrome-192x192.png public/apple-touch-icon.png public/favicon.ico
- Loading branch information
Showing
89 changed files
with
2,835 additions
and
92 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
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,35 @@ | ||
# Service dependencies | ||
REDIS_HOST=redis | ||
REDIS_PORT=6379 | ||
# REDIS_DB=0 | ||
DB_HOST=db | ||
DB_USER=postgres | ||
DB_PASS= | ||
|
||
# Federation | ||
LOCAL_DOMAIN=localhost:3000 | ||
LOCAL_HTTPS=false | ||
|
||
# Application secrets | ||
# Generate each with the `rake secret` task (`docker-compose run --rm web rake secret` if you use docker compose) | ||
PAPERCLIP_SECRET=RANDOM_STRING | ||
SECRET_KEY_BASE=RANDOM_STRING | ||
OTP_SECRET=RANDOM_STRING | ||
|
||
# VAPID keys (used for push notifications | ||
# You can generate the keys using the following command (first is the private key, second is the public one) | ||
# You should only generate this once per instance. If you later decide to change it, all push subscription will | ||
# be invalidated, requiring the users to access the website again to resubscribe. | ||
# | ||
# Generate with `rake mastodon:webpush:generate_vapid_key` task (`docker-compose run --rm web rake mastodon:webpush:generate_vapid_key` if you use docker compose) | ||
# | ||
# For more information visit https://rossta.net/blog/using-the-web-push-api-with-vapid.html | ||
VAPID_PRIVATE_KEY= | ||
VAPID_PUBLIC_KEY= | ||
|
||
# Cluster number setting for streaming API server. | ||
# If you comment out following line, cluster number will be `numOfCpuCores - 1`. | ||
STREAMING_CLUSTER_NUM=1 | ||
|
||
QIITA_CLIENT_ID= | ||
QIITA_CLIENT_SECRET= |
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,50 @@ | ||
FROM ruby:2.4.1-alpine | ||
|
||
LABEL maintainer="https://github.com/increments/mastodon" \ | ||
description="A GNU Social-compatible microblogging server" | ||
|
||
ENV UID=991 GID=991 | ||
|
||
EXPOSE 3000 4000 | ||
|
||
WORKDIR /mastodon | ||
|
||
RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \ | ||
&& apk -U upgrade \ | ||
&& apk add -t build-dependencies \ | ||
build-base \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
postgresql-dev \ | ||
protobuf-dev \ | ||
python \ | ||
&& apk add \ | ||
ca-certificates \ | ||
ffmpeg \ | ||
file \ | ||
git \ | ||
imagemagick@edge \ | ||
libpq \ | ||
libxml2 \ | ||
libxslt \ | ||
nodejs-npm@edge \ | ||
nodejs@edge \ | ||
protobuf \ | ||
su-exec \ | ||
tini \ | ||
&& npm install -g npm@3 && npm install -g yarn \ | ||
&& update-ca-certificates \ | ||
&& rm -rf /tmp/* /var/cache/apk/* | ||
|
||
COPY Gemfile Gemfile.lock package.json yarn.lock /mastodon/ | ||
|
||
RUN bundle install \ | ||
&& yarn --ignore-optional | ||
|
||
COPY . /mastodon | ||
|
||
COPY docker_entrypoint.sh /usr/local/bin/run | ||
|
||
RUN chmod +x /usr/local/bin/run | ||
|
||
ENTRYPOINT ["/usr/local/bin/run"] |
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
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
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
include AfterSignInPathLeadable | ||
|
||
def qiita | ||
auth_hash = request.env['omniauth.auth'] | ||
|
||
if current_user | ||
qiita_authorization = QiitaAuthorization.find_or_initialize_by(uid: auth_hash[:uid]) do |qiita_authorization| | ||
qiita_authorization.token = auth_hash[:credentials][:token] | ||
qiita_authorization.user = current_user | ||
end | ||
|
||
if qiita_authorization.save | ||
flash[:notice] = I18n.t('omniauth_callbacks.success') | ||
else | ||
flash[:alert] = I18n.t('omniauth_callbacks.failure') | ||
end | ||
redirect_to after_sign_in_path_for(current_user) | ||
else | ||
if authorization = QiitaAuthorization.find_by(uid: auth_hash[:uid]) | ||
sign_in(authorization.user) | ||
redirect_to after_sign_in_path_for(authorization.user) | ||
else | ||
store_omniauth_data | ||
redirect_to new_user_oauth_registration_path | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def store_omniauth_data | ||
session[:devise_omniauth_auth] = request.env['omniauth.auth'] | ||
session[:devise_omniauth_origin] = request.env['omniauth.origin'] | ||
end | ||
|
||
# @override | ||
def location_after_sign_in | ||
request.env['omniauth.origin'].presence || stored_location_for(:user) | ||
end | ||
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,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module AfterSignInPathLeadable | ||
extend ActiveSupport::Concern | ||
|
||
protected | ||
|
||
def after_sign_in_path_for(resource) | ||
after_sign_in_path = resolve_url(location_after_sign_in) | ||
|
||
if home_paths(resource).include?((after_sign_in_path || '').split('?').first) | ||
root_path | ||
else | ||
after_sign_in_path || root_path | ||
end | ||
end | ||
|
||
private | ||
|
||
def home_paths(resource) | ||
paths = [about_path] | ||
if single_user_mode? && resource.is_a?(User) | ||
paths << short_account_path(username: resource.account) | ||
end | ||
paths | ||
end | ||
|
||
def resolve_url(url) | ||
uri = URI.parse(url) | ||
if !uri.host || uri.host == request.host | ||
uri.query ? "#{uri.path}?#{uri.query}" : uri.path | ||
else | ||
nil | ||
end | ||
rescue URI::InvalidURIError => e | ||
nil | ||
end | ||
|
||
def location_after_sign_in | ||
fail NotImplementedError | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class OauthRegistrationsController < DeviseController | ||
include AfterSignInPathLeadable | ||
layout 'auth' | ||
|
||
before_action :check_enabled_registrations | ||
before_action :require_omniauth_auth | ||
before_action :require_no_authentication | ||
|
||
def new | ||
@oauth_registration = Form::OauthRegistration.from_omniauth_auth(omniauth_auth) | ||
end | ||
|
||
def create | ||
@oauth_registration = Form::OauthRegistration.from_omniauth_auth(omniauth_auth) | ||
@oauth_registration.assign_attributes( | ||
params.require(:form_oauth_registration).permit(:email, :username, :password, :password_confirmation).merge(locale: I18n.locale) | ||
) | ||
|
||
if @oauth_registration.save | ||
sign_in(@oauth_registration.user) | ||
redirect_to after_sign_in_path_for(@oauth_registration.user) | ||
flash[:notice] = I18n.t('oauth_registration.success') | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def omniauth_auth | ||
@omniauth_auth ||= session[:devise_omniauth_auth].try(:deep_symbolize_keys) | ||
end | ||
|
||
def check_enabled_registrations | ||
redirect_to root_path if single_user_mode? || !Setting.open_registrations | ||
end | ||
|
||
def require_omniauth_auth | ||
redirect_to root_path unless omniauth_auth | ||
end | ||
|
||
# @override | ||
def location_after_sign_in | ||
session[:devise_omniauth_origin].presence || stored_location_for(:user) | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/controllers/settings/qiita_authorizations_controller.rb
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class Settings::QiitaAuthorizationsController < ApplicationController | ||
layout 'admin' | ||
|
||
before_action :authenticate_user! | ||
|
||
def show | ||
@account = current_account | ||
@qiita_authorization = current_account.user.qiita_authorization | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module ThemeHelper | ||
def theme_param | ||
params[:theme] == 'dark' ? 'dark' : 'light' | ||
end | ||
|
||
def theme_class_name | ||
"theme-#{theme_param}" | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.