Skip to content

Commit

Permalink
* Renamed companies to organizations.
Browse files Browse the repository at this point in the history
* Renames accounts to auth.
  • Loading branch information
bgroff committed Aug 15, 2017
1 parent f1b4564 commit d10f8cc
Show file tree
Hide file tree
Showing 76 changed files with 210 additions and 250 deletions.
8 changes: 4 additions & 4 deletions django_kala/api/basecamp_classic/companies/serializers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from rest_framework import serializers
from companies.models import Company
from organizations.models import Organization


class CompanySerializer(serializers.ModelSerializer):
class Meta:
model = Company
model = Organization
fields = [
'id', 'uuid', 'name', 'website', 'phone', 'fax',
'address', 'address1', 'city', 'state', 'zip',
'country', 'timezone'
]

def create(self, validated_data):
return Company.objects.create(**validated_data)
return Organization.objects.create(**validated_data)

def validate_name(self, value):
# At least try to dedup names
if Company.objects.filter(name__iexact=value):
if Organization.objects.filter(name__iexact=value):
raise serializers.ValidationError('Name is already in use.')
return value
8 changes: 4 additions & 4 deletions django_kala/api/basecamp_classic/companies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework.response import Response
from rest_framework import authentication, permissions

from companies.models import Company
from organizations.models import Organization

from .parsers import XMLCompanyParser
from .renderers import XMLCompaniesRenderer
Expand Down Expand Up @@ -34,7 +34,7 @@ def get(self, request, format=None):
"""
Return an xml version of all of the companies.
"""
return Response({'companies': Company.objects.all(), 'request_user': request.user})
return Response({'companies': Organization.objects.all(), 'request_user': request.user})

def post(self, request, format=None):
if not request.user.is_admin:
Expand Down Expand Up @@ -64,7 +64,7 @@ def get(self, request, pk, format=None):
"""
Return a company by pk.
"""
company = get_object_or_404(Company, pk=pk)
company = get_object_or_404(Organization, pk=pk)
return Response({'companies': company, 'request_user': request.user})


Expand All @@ -85,5 +85,5 @@ def get(self, request, pk, format=None):
"""
Return a list of all users for a specific company.
"""
company = get_object_or_404(Company, pk=pk)
company = get_object_or_404(Organization, pk=pk)
return Response({'users': company.get_people(), 'request_user': request.user})
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/documents/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from accounts.models import User
from auth.models import User
from documents.models import Document, DocumentVersion
from projects.models import Category, Project

Expand Down
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/people/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _xml_convert(self, element):
data['fax'] = str(field.text)

if field.tag == 'company-id':
data['companies'] = [int(field.text)] if field.text else None
data['organizations'] = [int(field.text)] if field.text else None
if field.tag == 'client-id':
data['client_id'] = int(field.text) if field.text else None

Expand Down
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/people/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def render_person(self, user, request_user, xml):
xml.endElement('phone-number-fax')
xml.startElement('company-id', {'type': 'integer'})
try:
xml.characters(smart_text(user.companies.first().id if user.companies.first().id else ''))
xml.characters(smart_text(user.organizations.first().id if user.organizations.first().id else ''))
except AttributeError:
xml.characters(smart_text(''))
xml.endElement('company-id')
Expand Down
4 changes: 2 additions & 2 deletions django_kala/api/basecamp_classic/people/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Meta:
fields = (
'id', 'first_name', 'last_name', 'email', 'username',
'avatar_url', 'date_joined', 'is_active', 'is_admin',
'companies'
'organizations'
)

def create(self, validated_data):
companies = validated_data.pop('companies')
user = User.objects.create(**validated_data)
user.companies.add(*companies)
user.organizations.add(*companies)
return user
4 changes: 2 additions & 2 deletions django_kala/api/basecamp_classic/projects/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def _xml_convert(self, element):
if field.tag == 'company':
for _field in field:
if _field.tag == 'id':
data['company'] = int(str(_field.text).strip())
data['organization'] = int(str(_field.text).strip())
if field.tag == 'name':
data['company_name'] = str(_field.text)
data['organization_name'] = str(_field.text)

return data

Expand Down
8 changes: 4 additions & 4 deletions django_kala/api/basecamp_classic/projects/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):

xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
# If we do not have companies or request_user then we have errors
# If we do not have organizations or request_user then we have errors
if not data.get('projects', False) and not data.get('request_user', False):
self._to_errors(data, xml)
xml.endDocument()
Expand All @@ -40,7 +40,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
self._to_xml(data['projects'], data['request_user'], xml)

xml.endElement('projects')
# Otherwise just render a company
# Otherwise just render a organization
else:
self.render_projects(data['projects'], data['request_user'], xml)
xml.endDocument()
Expand Down Expand Up @@ -107,10 +107,10 @@ def render_projects(self, project, request_user, xml):
xml.startElement('company', {})

xml.startElement('id', {'type': 'integer'})
xml.characters(smart_text(project.company.id))
xml.characters(smart_text(project.organization.id))
xml.endElement('id')
xml.startElement('name', {})
xml.characters(smart_text(project.company.name))
xml.characters(smart_text(project.organization.name))
xml.endElement('name')

xml.endElement('company')
Expand Down
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = [
'id', 'name', 'company'
'id', 'name', 'organization'
]

def create(self, validated_data):
Expand Down
2 changes: 1 addition & 1 deletion django_kala/api/basecamp_classic/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ProjectView(APIView):

def get(self, request, pk, format=None):
"""
Return a company by pk.
Return a project by pk.
"""
project = get_object_or_404(Project, pk=pk)
return Response({'projects': project, 'request_user': request.user})
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions django_kala/auth/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthConfig(AppConfig):
name = 'auth'
label = 'kala_auth'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django import forms
from django.contrib.auth import get_user_model

from companies.models import Company
from organizations.models import Organization
from projects.models import Project


Expand Down Expand Up @@ -47,12 +47,12 @@ def __init__(self, *args, **kwargs):
del self.fields['new_password']
del self.fields['confirm']

company = forms.ModelChoiceField(queryset=Company.objects.active(), widget=forms.Select(attrs={'class': 'span3'}))
organizations = forms.ModelChoiceField(queryset=Organization.objects.active(), widget=forms.Select(attrs={'class': 'span3'}))

class Meta:
model = get_user_model()
fields = (
'email', 'first_name', 'last_name', 'company'
'email', 'first_name', 'last_name', 'organizations'
)

def clean_email(self):
Expand All @@ -66,42 +66,42 @@ def save(self, *args, **kwargs):
self.instance.username = self.cleaned_data['email']
self.instance.set_unusable_password()
self.instance.is_active = True
self.instance.company = self.cleaned_data['company']
self.instance.Organization = self.cleaned_data['prganization']
return super(CreatePersonForm, self).save(*args, **kwargs)


class DeletedCompanyForm(forms.Form):
company = forms.ModelChoiceField(queryset=Company.objects.deleted(),
organization = forms.ModelChoiceField(queryset=Organization.objects.deleted(),
widget=forms.Select(attrs={'class': 'span3'}))

def save(self):
company = self.cleaned_data['company']
company.set_active(True)
return company
organization = self.cleaned_data['organization']
organization.set_active(True)
return organization


def permission_forms(request, person):
return [PermissionsForm(request.POST or None, person=person, company=company) for company in
Company.objects.active().filter(pk__in=Project.objects.active().values('company__pk'))]
return [PermissionsForm(request.POST or None, person=person, organization=organization) for organization in
Organization.objects.active().filter(pk__in=Project.objects.active().values('organization__pk'))]


class PermissionsForm(forms.Form):
def __init__(self, *args, **kwargs):
self.person = kwargs.pop('person')
self.company = kwargs.pop('company')
self.projects = Project.objects.active().filter(company=self.company)
self.organization = kwargs.pop('organization')
self.projects = Project.objects.active().filter(organization=self.organization)
super(PermissionsForm, self).__init__(*args, **kwargs)
self.fields[self.company] = forms.BooleanField(required=False, label='Select/Unselect All',
self.fields[self.organization] = forms.BooleanField(required=False, label='Select/Unselect All',
widget=forms.CheckboxInput(
attrs={'class': 'company_checkbox',
'pk_id': self.company.pk,
attrs={'class': 'organization_checkbox',
'pk_id': self.organization.pk,
}))
for project in self.projects:
self.fields['%i' % project.pk] = forms.BooleanField(required=False, label=project,
initial=True if project.clients.filter(
pk=self.person.pk).exists() else False,
widget=forms.CheckboxInput(
attrs={'pk': self.company.pk}))
attrs={'pk': self.organization.pk}))

def save(self):
for project in self.projects:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class InviteUserForm(forms.ModelForm):

class Meta:
model = get_user_model()
fields = ['email', 'companies']
fields = ['email', 'organizations']
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-04-10 06:02
# Generated by Django 1.11.2 on 2017-08-15 02:29
from __future__ import unicode_literals

import django.contrib.auth.models
Expand All @@ -16,8 +16,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('companies', '0001_initial'),
('auth', '0008_alter_user_username_max_length'),
('organizations', '__first__'),
]

operations = [
Expand All @@ -31,10 +31,10 @@ class Migration(migrations.Migration):
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, unique=True)),
('title', models.CharField(blank=True, max_length=255, null=True)),
('timezone', timezone_field.fields.TimeZoneField(blank=True, default='UTC')),
Expand All @@ -48,13 +48,13 @@ class Migration(migrations.Migration):
('last_updated', models.DateTimeField(auto_now=True)),
('removed', models.DateField(null=True)),
('avatar_url', models.URLField(max_length=1200)),
('companies', models.ManyToManyField(to='companies.Company')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('organizations', models.ManyToManyField(to='organizations.Organization')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'db_table': 'kala_person',
'ordering': ['first_name', 'last_name'],
'db_table': 'kala_person',
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
Expand Down
File renamed without changes.
26 changes: 13 additions & 13 deletions django_kala/accounts/models.py → django_kala/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from timezone_field import TimeZoneField
from uuid import uuid4

import companies
import organizations
import projects
import datetime

Expand All @@ -16,7 +16,7 @@ class User(AbstractUser):

uuid = models.UUIDField(unique=True, db_index=True, default=uuid4)
title = models.CharField(max_length=255, null=True, blank=True)
companies = models.ManyToManyField('companies.Company')
organizations = models.ManyToManyField('organizations.Organization')
timezone = TimeZoneField(default=settings.TIME_ZONE, blank=True)
access_new_projects = models.BooleanField(default=False)

Expand Down Expand Up @@ -48,35 +48,35 @@ def set_active(self, active):
self.removed = datetime.date.today()
self.save()

def get_companies(self, has_projects=True):
def get_organizations(self, has_projects=True):
if self.is_admin:
_companies = companies.models.Company.objects.active()
_organizations = organizations.models.Organization.objects.active()
else:
_companies = companies.models.Company.objects.active().filter(
_organizations = organizations.models.Organization.objects.active().filter(
pk__in=projects.models.Project.clients.through.objects.filter(
user__pk=self.pk
).values('project__company__pk')
).values('project__organization__pk')
)
if has_projects:
has_projects = companies.models.Company.objects.active().filter(
pk__in=projects.models.Project.objects.active().values('company__pk'))
return _companies & has_projects
return _companies
has_projects = organizations.models.Organization.objects.active().filter(
pk__in=projects.models.Project.objects.active().values('organization__pk'))
return _organizations & has_projects
return _organizations

def get_projects(self):
if self.is_admin:
return projects.models.Project.objects.active()
else:
return projects.models.Project.objects.active().filter(
company__id=self.get_companies().values_list('company__pk')
organization__id=self.get_organizations().values_list('organization__pk')
)

def get_users(self):
if self.is_admin:
return User.objects.all()
else:
companies = self.get_companies().values_list('pk')
return User.objects.filter(companies__in=companies)
organizations = self.get_organizations().values_list('pk')
return User.objects.filter(organizations__in=organizations)

def send_invite(self):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ <h2 class="active section">Invite
{{ form.email }}
</div>
<div class="field">
<label>{{ form.companies.label }}</label>
{{ form.companies }}
<label>{{ form.organizations.label }}</label>
{{ form.organizations }}
</div>
<button id="submit-button" class="ui button primary" type="submit">Invite user</button>
</form>
Expand Down
File renamed without changes.

0 comments on commit d10f8cc

Please sign in to comment.