Skip to content

Commit f6df9d0

Browse files
committed
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
2 parents 559fd08 + ef27a0b commit f6df9d0

89 files changed

Lines changed: 2835 additions & 92 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.production.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ SMTP_FROM_ADDRESS=notifications@example.com
112112
# If you comment out following line, cluster number will be `numOfCpuCores - 1`.
113113
STREAMING_CLUSTER_NUM=1
114114

115+
SENTRY_DSN=
116+
117+
QIITA_CLIENT_ID=
118+
QIITA_CLIENT_SECRET=
119+
115120
# Docker mastodon user
116121
# If you use Docker, you may want to assign UID/GID manually.
117122
# UID=1000

.env.sample

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Service dependencies
2+
REDIS_HOST=redis
3+
REDIS_PORT=6379
4+
# REDIS_DB=0
5+
DB_HOST=db
6+
DB_USER=postgres
7+
DB_PASS=
8+
9+
# Federation
10+
LOCAL_DOMAIN=localhost:3000
11+
LOCAL_HTTPS=false
12+
13+
# Application secrets
14+
# Generate each with the `rake secret` task (`docker-compose run --rm web rake secret` if you use docker compose)
15+
PAPERCLIP_SECRET=RANDOM_STRING
16+
SECRET_KEY_BASE=RANDOM_STRING
17+
OTP_SECRET=RANDOM_STRING
18+
19+
# VAPID keys (used for push notifications
20+
# You can generate the keys using the following command (first is the private key, second is the public one)
21+
# You should only generate this once per instance. If you later decide to change it, all push subscription will
22+
# be invalidated, requiring the users to access the website again to resubscribe.
23+
#
24+
# 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)
25+
#
26+
# For more information visit https://rossta.net/blog/using-the-web-push-api-with-vapid.html
27+
VAPID_PRIVATE_KEY=
28+
VAPID_PUBLIC_KEY=
29+
30+
# Cluster number setting for streaming API server.
31+
# If you comment out following line, cluster number will be `numOfCpuCores - 1`.
32+
STREAMING_CLUSTER_NUM=1
33+
34+
QIITA_CLIENT_ID=
35+
QIITA_CLIENT_SECRET=

Dockerfile-development

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM ruby:2.4.1-alpine
2+
3+
LABEL maintainer="https://github.com/increments/mastodon" \
4+
description="A GNU Social-compatible microblogging server"
5+
6+
ENV UID=991 GID=991
7+
8+
EXPOSE 3000 4000
9+
10+
WORKDIR /mastodon
11+
12+
RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
13+
&& apk -U upgrade \
14+
&& apk add -t build-dependencies \
15+
build-base \
16+
libxml2-dev \
17+
libxslt-dev \
18+
postgresql-dev \
19+
protobuf-dev \
20+
python \
21+
&& apk add \
22+
ca-certificates \
23+
ffmpeg \
24+
file \
25+
git \
26+
imagemagick@edge \
27+
libpq \
28+
libxml2 \
29+
libxslt \
30+
nodejs-npm@edge \
31+
nodejs@edge \
32+
protobuf \
33+
su-exec \
34+
tini \
35+
&& npm install -g npm@3 && npm install -g yarn \
36+
&& update-ca-certificates \
37+
&& rm -rf /tmp/* /var/cache/apk/*
38+
39+
COPY Gemfile Gemfile.lock package.json yarn.lock /mastodon/
40+
41+
RUN bundle install \
42+
&& yarn --ignore-optional
43+
44+
COPY . /mastodon
45+
46+
COPY docker_entrypoint.sh /usr/local/bin/run
47+
48+
RUN chmod +x /usr/local/bin/run
49+
50+
ENTRYPOINT ["/usr/local/bin/run"]

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ gem 'link_header', '~> 0.0'
4141
gem 'mime-types', '~> 3.1'
4242
gem 'nokogiri', '~> 1.7'
4343
gem 'oj', '~> 3.0'
44+
gem 'omniauth', '~> 1.6'
45+
gem 'omniauth_qiita', '~> 0.1'
4446
gem 'ostatus2', '~> 2.0'
4547
gem 'ox', '~> 2.5'
4648
gem 'pundit', '~> 1.1'
@@ -55,6 +57,7 @@ gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock'
5557
gem 'rqrcode', '~> 0.10'
5658
gem 'ruby-oembed', '~> 0.12', require: 'oembed'
5759
gem 'sanitize', '~> 4.4'
60+
gem 'sentry-raven', '~> 2.4'
5861
gem 'sidekiq', '~> 5.0'
5962
gem 'sidekiq-scheduler', '~> 2.1'
6063
gem 'sidekiq-unique-jobs', '~> 5.0'

Gemfile.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ GEM
158158
fabrication (2.16.1)
159159
faker (1.7.3)
160160
i18n (~> 0.5)
161+
faraday (0.11.0)
162+
multipart-post (>= 1.2, < 3)
161163
fast_blank (1.0.0)
162164
ffi (1.9.18)
163165
fuubar (2.2.0)
@@ -180,6 +182,7 @@ GEM
180182
hamlit (>= 1.2.0)
181183
railties (>= 4.0.1)
182184
hashdiff (0.3.4)
185+
hashie (3.5.5)
183186
highline (1.7.8)
184187
hiredis (0.6.1)
185188
hkdf (0.3.0)
@@ -256,6 +259,8 @@ GEM
256259
minitest (5.10.2)
257260
msgpack (1.1.0)
258261
multi_json (1.12.1)
262+
multi_xml (0.6.0)
263+
multipart-post (2.0.0)
259264
net-scp (1.2.1)
260265
net-ssh (>= 2.6.5)
261266
net-ssh (4.1.0)
@@ -264,7 +269,22 @@ GEM
264269
mini_portile2 (~> 2.2.0)
265270
nokogumbo (1.4.13)
266271
nokogiri
272+
oauth2 (1.3.1)
273+
faraday (>= 0.8, < 0.12)
274+
jwt (~> 1.0)
275+
multi_json (~> 1.3)
276+
multi_xml (~> 0.5)
277+
rack (>= 1.2, < 3)
267278
oj (3.2.0)
279+
omniauth (1.6.1)
280+
hashie (>= 3.4.6, < 3.6.0)
281+
rack (>= 1.6.2, < 3)
282+
omniauth-oauth2 (1.4.0)
283+
oauth2 (~> 1.0)
284+
omniauth (~> 1.2)
285+
omniauth_qiita (0.1.0)
286+
multi_json (~> 1.10)
287+
omniauth-oauth2 (~> 1.2)
268288
openssl (2.0.4)
269289
orm_adapter (0.5.0)
270290
ostatus2 (2.0.1)
@@ -413,6 +433,8 @@ GEM
413433
scss_lint (0.54.0)
414434
rake (>= 0.9, < 13)
415435
sass (~> 3.4.20)
436+
sentry-raven (2.4.0)
437+
faraday (>= 0.7.6, < 1.0)
416438
sidekiq (5.0.3)
417439
concurrent-ruby (~> 1.0)
418440
connection_pool (~> 2.2, >= 2.2.0)
@@ -541,6 +563,8 @@ DEPENDENCIES
541563
mime-types (~> 3.1)
542564
nokogiri (~> 1.7)
543565
oj (~> 3.0)
566+
omniauth (~> 1.6)
567+
omniauth_qiita (~> 0.1)
544568
ostatus2 (~> 2.0)
545569
ox (~> 2.5)
546570
paperclip (~> 5.1)
@@ -570,6 +594,7 @@ DEPENDENCIES
570594
ruby-oembed (~> 0.12)
571595
sanitize (~> 4.4)
572596
scss_lint (~> 0.53)
597+
sentry-raven (~> 2.4)
573598
sidekiq (~> 5.0)
574599
sidekiq-bulk (~> 0.1.1)
575600
sidekiq-scheduler (~> 2.1)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
**Please read this page to develop -> https://github.com/increments/mastodon/wiki**
2+
13
![Mastodon](https://i.imgur.com/NhZc40l.png)
2-
========
4+
=======
35

46
[![Build Status](http://img.shields.io/travis/tootsuite/mastodon.svg)][travis]
57
[![Code Climate](https://img.shields.io/codeclimate/github/tootsuite/mastodon.svg)][code_climate]

app/controllers/admin/settings_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SettingsController < BaseController
1919
open_registrations
2020
open_deletion
2121
timeline_preview
22+
prohibit_registrations_except_qiita_oauth
2223
).freeze
2324

2425
def edit
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4+
include AfterSignInPathLeadable
5+
6+
def qiita
7+
auth_hash = request.env['omniauth.auth']
8+
9+
if current_user
10+
qiita_authorization = QiitaAuthorization.find_or_initialize_by(uid: auth_hash[:uid]) do |qiita_authorization|
11+
qiita_authorization.token = auth_hash[:credentials][:token]
12+
qiita_authorization.user = current_user
13+
end
14+
15+
if qiita_authorization.save
16+
flash[:notice] = I18n.t('omniauth_callbacks.success')
17+
else
18+
flash[:alert] = I18n.t('omniauth_callbacks.failure')
19+
end
20+
redirect_to after_sign_in_path_for(current_user)
21+
else
22+
if authorization = QiitaAuthorization.find_by(uid: auth_hash[:uid])
23+
sign_in(authorization.user)
24+
redirect_to after_sign_in_path_for(authorization.user)
25+
else
26+
store_omniauth_data
27+
redirect_to new_user_oauth_registration_path
28+
end
29+
end
30+
end
31+
32+
private
33+
34+
def store_omniauth_data
35+
session[:devise_omniauth_auth] = request.env['omniauth.auth']
36+
session[:devise_omniauth_origin] = request.env['omniauth.origin']
37+
end
38+
39+
# @override
40+
def location_after_sign_in
41+
request.env['omniauth.origin'].presence || stored_location_for(:user)
42+
end
43+
end

app/controllers/auth/registrations_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ def after_inactive_sign_up_path_for(_resource)
3434
end
3535

3636
def check_enabled_registrations
37-
redirect_to root_path if single_user_mode? || !Setting.open_registrations
37+
redirect_to root_path if single_user_mode? || !Setting.open_registrations || Setting.prohibit_registrations_except_qiita_oauth
38+
end
39+
40+
def update_resource(resource, params)
41+
if resource.try(:has_dummy_password?)
42+
resource.update_without_current_password(params)
43+
else
44+
super
45+
end
3846
end
3947

4048
private
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module AfterSignInPathLeadable
4+
extend ActiveSupport::Concern
5+
6+
protected
7+
8+
def after_sign_in_path_for(resource)
9+
after_sign_in_path = resolve_url(location_after_sign_in)
10+
11+
if home_paths(resource).include?((after_sign_in_path || '').split('?').first)
12+
root_path
13+
else
14+
after_sign_in_path || root_path
15+
end
16+
end
17+
18+
private
19+
20+
def home_paths(resource)
21+
paths = [about_path]
22+
if single_user_mode? && resource.is_a?(User)
23+
paths << short_account_path(username: resource.account)
24+
end
25+
paths
26+
end
27+
28+
def resolve_url(url)
29+
uri = URI.parse(url)
30+
if !uri.host || uri.host == request.host
31+
uri.query ? "#{uri.path}?#{uri.query}" : uri.path
32+
else
33+
nil
34+
end
35+
rescue URI::InvalidURIError => e
36+
nil
37+
end
38+
39+
def location_after_sign_in
40+
fail NotImplementedError
41+
end
42+
end

0 commit comments

Comments
 (0)