-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1121 from rdmorganiser/interview-visibility
feat(interview): Project visibility [1]
- Loading branch information
Showing
43 changed files
with
1,678 additions
and
451 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
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
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,32 @@ | ||
# Generated by Django 4.2.16 on 2024-12-06 10:11 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0012_alter_user_first_name_max_length'), | ||
('sites', '0002_alter_domain_unique'), | ||
('projects', '0061_alter_value_value_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Visibility', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', models.DateTimeField(editable=False, verbose_name='created')), | ||
('updated', models.DateTimeField(editable=False, verbose_name='updated')), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups for which the project is visible.', to='auth.group', verbose_name='Group')), | ||
('project', models.OneToOneField(help_text='The project for this visibility.', on_delete=django.db.models.deletion.CASCADE, to='projects.project', verbose_name='Project')), | ||
('sites', models.ManyToManyField(blank=True, help_text='The sites for which the project is visible (in a multi site setup).', to='sites.site', verbose_name='Sites')), | ||
], | ||
options={ | ||
'verbose_name': 'Visibility', | ||
'verbose_name_plural': 'Visibilities', | ||
'ordering': ('project',), | ||
}, | ||
), | ||
] |
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,66 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import Group | ||
from django.contrib.sites.models import Site | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.utils.translation import ngettext_lazy | ||
|
||
from rdmo.core.models import Model | ||
|
||
|
||
class Visibility(Model): | ||
|
||
project = models.OneToOneField( | ||
'Project', on_delete=models.CASCADE, | ||
verbose_name=_('Project'), | ||
help_text=_('The project for this visibility.') | ||
) | ||
sites = models.ManyToManyField( | ||
Site, blank=True, | ||
verbose_name=_('Sites'), | ||
help_text=_('The sites for which the project is visible (in a multi site setup).') | ||
) | ||
groups = models.ManyToManyField( | ||
Group, blank=True, | ||
verbose_name=_('Group'), | ||
help_text=_('The groups for which the project is visible.') | ||
) | ||
|
||
class Meta: | ||
ordering = ('project', ) | ||
verbose_name = _('Visibility') | ||
verbose_name_plural = _('Visibilities') | ||
|
||
def __str__(self): | ||
return str(self.project) | ||
|
||
def is_visible(self, user): | ||
return ( | ||
not self.sites.exists() or self.sites.filter(id=settings.SITE_ID).exists() | ||
) and ( | ||
not self.groups.exists() or self.groups.filter(id__in=[group.id for group in user.groups.all()]).exists() | ||
) | ||
|
||
def get_help_display(self): | ||
sites = self.sites.values_list('domain', flat=True) | ||
groups = self.groups.values_list('name', flat=True) | ||
|
||
if sites and groups: | ||
return ngettext_lazy( | ||
'This project can be accessed by all users on %s or in the group %s.', | ||
'This project can be accessed by all users on %s or in the groups %s.', | ||
len(groups) | ||
) % ( | ||
', '.join(sites), | ||
', '.join(groups) | ||
) | ||
elif sites: | ||
return _('This project can be accessed by all users on %s.') % ', '.join(sites) | ||
elif groups: | ||
return ngettext_lazy( | ||
'This project can be accessed by all users in the group %s.', | ||
'This project can be accessed by all users in the groups %s.', | ||
len(groups) | ||
) % ', '.join(groups) | ||
else: | ||
return _('This project can be accessed by all users.') |
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
Oops, something went wrong.