forked from OSQA/osqa
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds setting PER_EMAIL_DOMAIN_GROUPS_ENABLED - adds setting PER_EMAIL_DOMAIN_GROUP_DEFAULT_VISIBILITY - visibility of groups created for email domains options: 0 - admins, 1 - mods, 2 - members + admins and mods, 3 - public (default) * askbot/const/__init__.py: - adds constants for group visibility, PEP8 * askbot/models/analytics.py: - adds models for daily summaries for users and groups - models BaseSummary (abstract), DailySummary (abstract), UserDailySummary, GroupDailySummary * askbot/models/user.py: - adds function get_organization_name_from_domain - adds visibility field to Askbot Group * adds management command askbot_create_per_email_domain_groups * migration 0028: - adds UserDailySummary and GroupDailySummary models * migration 0029: - adds visibility field to the Askbot Group model todo: add tests for the askbot_create_per_email_domain_groups, Group.objects.get_or_create
- Loading branch information
1 parent
1a12ac8
commit 5f1a856
Showing
8 changed files
with
196 additions
and
17 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
"""Group settings""" | ||
from django.utils.translation import gettext_lazy as _ | ||
from livesettings import values as livesettings | ||
from askbot.conf.settings_wrapper import settings | ||
from askbot.conf.super_groups import LOGIN_USERS_COMMUNICATION | ||
from livesettings import values as livesettings | ||
from askbot import const | ||
|
||
GROUP_SETTINGS = livesettings.ConfigurationGroup( | ||
'GROUP_SETTINGS', | ||
|
@@ -64,3 +65,24 @@ def group_name_update_callback(old_name, new_name): | |
'"[email protected]"') | ||
) | ||
) | ||
|
||
settings.register( | ||
livesettings.BooleanValue( | ||
GROUP_SETTINGS, | ||
'PER_EMAIL_DOMAIN_GROUPS_ENABLED', | ||
default=False, | ||
description=_('Enable per email domain user groups'), | ||
help_text=_('If enabled, groups will be created for each email domain name') | ||
) | ||
) | ||
|
||
settings.register( | ||
livesettings.StringValue( | ||
GROUP_SETTINGS, | ||
'PER_EMAIL_DOMAIN_GROUP_DEFAULT_VISIBILITY', | ||
choices=const.GROUP_VISIBILITY_CHOICES, | ||
default=const.GROUP_VISIBILITY_PUBLIC, | ||
description=_('Default visibility of groups created for the email domains'), | ||
help_text=_('Administrators can change the visibility of these groups individually later') | ||
) | ||
) |
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
27 changes: 27 additions & 0 deletions
27
askbot/management/commands/askbot_create_per_email_domain_groups.py
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,27 @@ | ||
"""A management command that creates groups for each email domain in the database.""" | ||
from django.core.management.base import BaseCommand | ||
from askbot.conf import settings | ||
from askbot.models import User | ||
from askbot.models.analytics import get_organization_domains | ||
from askbot.models.user import get_organization_name_from_domain | ||
from askbot.utils.console import ProgressBar | ||
|
||
class Command(BaseCommand): # pylint: disable=missing-docstring | ||
help = 'Create groups for each email domain in the database.' | ||
|
||
def handle(self, *args, **options): # pylint: disable=missing-docstring, unused-argument | ||
"""Obtains a list of unique email domains names. | ||
Creates a group for each domain name, if such group does not exist. | ||
Group visibility is set to the value of settings.PER_EMAIL_DOMAIN_GROUP_DEFAULT_VISIBILITY. | ||
""" | ||
domains = get_organization_domains() | ||
count = len(domains) | ||
message = 'Initializing groups by the email address domain names' | ||
for domain in ProgressBar(domains, count, message): | ||
organization_name = get_organization_name_from_domain(domain) | ||
group = User.objects.get_or_create_group( | ||
organization_name, | ||
visibility=settings.PER_EMAIL_DOMAIN_GROUP_DEFAULT_VISIBILITY | ||
) | ||
print('Group {0} created.'.format(group.name)) | ||
|
51 changes: 51 additions & 0 deletions
51
askbot/migrations/0028_userdailysummary_groupdailysummary.py
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,51 @@ | ||
# Generated by Django 4.2.4 on 2024-06-24 21:15 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('askbot', '0027_populate_analytics_events'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserDailySummary', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('num_questions', models.PositiveIntegerField()), | ||
('num_answers', models.PositiveIntegerField()), | ||
('num_upvotes', models.PositiveIntegerField()), | ||
('num_downvotes', models.PositiveIntegerField()), | ||
('question_views', models.PositiveIntegerField()), | ||
('time_on_site', models.DurationField()), | ||
('date', models.DateField(db_index=True)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='GroupDailySummary', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('num_questions', models.PositiveIntegerField()), | ||
('num_answers', models.PositiveIntegerField()), | ||
('num_upvotes', models.PositiveIntegerField()), | ||
('num_downvotes', models.PositiveIntegerField()), | ||
('question_views', models.PositiveIntegerField()), | ||
('time_on_site', models.DurationField()), | ||
('date', models.DateField(db_index=True)), | ||
('num_users', models.PositiveIntegerField()), | ||
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='askbot.group')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
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,18 @@ | ||
# Generated by Django 4.2.4 on 2024-06-24 21:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('askbot', '0028_userdailysummary_groupdailysummary'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='group', | ||
name='visibility', | ||
field=models.SmallIntegerField(choices=[(0, 'Visible to administrators'), (1, 'Visible to moderators and administrators'), (2, 'Visible to own members, moderators and administrators'), (3, 'Visible to everyone')], default=3), | ||
), | ||
] |
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