Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1082 from kawazrepos/develop
Browse files Browse the repository at this point in the history
2016年09月04日のリリース
  • Loading branch information
giginet committed Sep 4, 2016
2 parents 947077d + 728d728 commit 9c6ee02
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ django-contrib-comments
django-debug-toolbar
django-debug-toolbar-template-timings
django-debug-toolbar-vcs-info>=1.1.0
django-slack-invitation
requests
django-appconf
honcho
Expand Down
7 changes: 7 additions & 0 deletions src/kawaz/apps/products/fixtures/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@
pk: 12
fields:
label: その他ゲーム
order: 99
- model: products.category
pk: 13
fields:
label: その他企画
order: 100
- model: products.category
pk: 14
fields:
label: Kawaz Compilation
order: 10
- model: products.platform
pk: 1
fields:
Expand Down
21 changes: 21 additions & 0 deletions src/kawaz/core/personas/models/persona.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import re
import os
import logging

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.base import ModelBase
from django.contrib.auth.models import AbstractUser
Expand Down Expand Up @@ -230,3 +232,22 @@ def get_absolute_url(self):
from ..activities.persona import PersonaActivityMediator
from activities.registry import registry
registry.register(Persona, PersonaActivityMediator())

from django.dispatch import receiver
from slack_invitation.slack import SlackInvitationClient, SlackInvitationException
from registration.signals import user_accepted


@receiver(user_accepted)
def invite_to_slack(user, profile, request, **kwargs):
try:
team = getattr(settings, 'DJANGO_SLACK_INVITATION_TEAM', None)
token = getattr(settings, 'DJANGO_SLACK_INVITATION_TOKEN', None)
if not team or not token:
raise ImproperlyConfigured('Both DJANGO_SLACK_INVITATION_TEAM and '
'DJANGO_SLACK_INVITATION_TOKEN must be set')
client = SlackInvitationClient(team, token)
client.invite(user.email)
except (ImproperlyConfigured, SlackInvitationException) as e:
logger = logging.getLogger(__name__)
logger.error(e)
27 changes: 26 additions & 1 deletion src/kawaz/core/personas/tests/test_models/test_persona.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.test import TestCase
from unittest.mock import patch
from django.test import TestCase, override_settings
from django.core.exceptions import ValidationError
from registration.backends.default import DefaultRegistrationBackend
from registration.tests.mock import mock_request
from slack_invitation.slack import SlackInvitationClient

from ..factories import PersonaFactory
from kawaz.core.personas.models import Persona, PersonaManager
Expand Down Expand Up @@ -101,3 +105,24 @@ def test_is_superuser_return_corresponding_value(self):
self.assertFalse(user.is_superuser)
user = PersonaFactory(role='wille')
self.assertFalse(user.is_superuser)

@override_settings(
DJANGO_SLACK_INVITATION_TEAM='teamname',
DJANGO_SLACK_INVITATION_TOKEN='token'
)
def test_invite_to_slack(self):
"""
Personaがacceptされたとき、Slackに自動的に招待する
"""
request = mock_request()
backend = DefaultRegistrationBackend()

with patch.object(SlackInvitationClient, 'invite') as invite:
new_user = backend.register(
username='bob', email='bob@example.com',
request=request)

profile = new_user.registration_profile
backend.accept(profile, request=request)

invite.assert_called_with('bob@example.com')
3 changes: 2 additions & 1 deletion src/kawaz/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'crispy_forms',
'compressor',
'activities',
'slack_invitation',
'google_calendar',
'kawaz.core.management',
'kawaz.core.db',
Expand Down Expand Up @@ -361,7 +362,7 @@ def show_debug_toolbar(request):
}

# 神、いわゆるゴッド
GEEKDRUMS_NAME = 'CollapsedPlug, lyrica09, miio'
GEEKDRUMS_NAME = 'miio'

# 環境依存の設定(デプロイサーバー固有の設定など)を読み込む
LOCAL_SETTINGS_LOADED = False
Expand Down

0 comments on commit 9c6ee02

Please sign in to comment.