- Fixed community edit audit logs being created even if the user owns the community.
- Simple ban page that shows you the reason, expiration date, and time left.
- Removing unused models
- other small changes
This commit is contained in:
some weird guy
2023-09-18 16:46:28 -07:00
parent e45ec4d1be
commit 328485d04c
9 changed files with 482 additions and 62 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ class CommentAdmin(admin.ModelAdmin):
class CommunityAdmin(admin.ModelAdmin):
raw_id_fields = ('creator', )
list_display = ('id', 'name', 'description', 'type', 'creator', 'popularity', 'is_rm', 'is_feature', 'require_auth')
search_fields = ('id', 'name', 'description', )
search_fields = ('id', 'name', 'description', 'creator')
actions = [Hide_content, Show_content, Feature_community, Unfeature_community, force_login, unforce_login]
list_filter = ('type', 'is_rm', 'is_feature', 'require_auth')
def get_queryset(self, request):
+10 -10
View File
@@ -1,6 +1,6 @@
from django.http import HttpResponseForbidden
from closedverse import settings
from django.shortcuts import redirect
from django.shortcuts import redirect, render
from .models import Ban
from django.utils import timezone
from re import compile
@@ -52,19 +52,19 @@ class CheckForBanMiddleware:
active_user_ban = Ban.objects.filter(
to=request.user,
active=True,
expiry_date__gte=timezone.now()
).first()
if active_user_ban:
return HttpResponseForbidden('You are banned from this site. Reason: ' + active_user_ban.reason)
expiry_date__gte=timezone.now()).first()
if active_user_ban:
context = {'ban': active_user_ban}
return render(request, 'ban.html', context)
# Get one active ban that is not expired for the IP address
ip_address = request.META.get('REMOTE_ADDR')
active_ip_ban = Ban.objects.filter(
ip_address=ip_address,
active=True,
expiry_date__gte=timezone.now(),
).first()
ip_address=ip_address,
active=True,
expiry_date__gte=timezone.now(),).first()
if active_ip_ban:
return HttpResponseForbidden('Your IP address is banned from this site. Reason: ' + active_ip_ban.reason)
context = {'ban': active_ip_ban}
return render(request, 'ban.html', context)
return None
class ClosedMiddleware(object):
+428
View File
@@ -0,0 +1,428 @@
# Generated by Django 3.2.2 on 2023-09-16 19:39
import closedverse_main.models
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('username', models.CharField(max_length=32, unique=True)),
('nickname', models.CharField(max_length=64, null=True)),
('password', models.CharField(max_length=128)),
('email', models.EmailField(blank=True, default='', max_length=254, null=True)),
('has_mh', models.BooleanField(default=False, help_text="Don't touch this. This is if the user's avatar is set to a Mii.")),
('avatar', models.CharField(blank=True, default='', max_length=1200)),
('theme', closedverse_main.models.ColorField(blank=True, max_length=18, null=True)),
('level', models.SmallIntegerField(default=0, help_text='This is the level of authority. People with a lower level cannot edit those with a higher level. This also grants additional permissions outside of the Django Admin Panel.')),
('addr', models.CharField(blank=True, max_length=64, null=True)),
('signup_addr', models.CharField(blank=True, max_length=64, null=True)),
('c_tokens', models.IntegerField(default=1, help_text='How many communities should this user be allowed to make?')),
('hide_online', models.BooleanField(default=False, help_text='If this is ticked, the user has opted to hide their online status.')),
('color', closedverse_main.models.ColorField(blank=True, default='', max_length=18, null=True)),
('is_staff', models.BooleanField(default=False, help_text="Allow this user to access the admin panel you're using right now?")),
('is_active', models.BooleanField(default=True, help_text="If this is off, the user is basically banned and can't do shit here")),
('is_superuser', models.BooleanField(default=False, help_text="Overrides django groups. This also allows you to change people's perms.")),
('can_invite', models.BooleanField(default=True, help_text='Can this user invite new users? This does not matter unless the invite system is turned on.')),
('bg_url', models.CharField(blank=True, max_length=300, null=True)),
('last_login', models.DateTimeField(auto_now=True)),
('created', models.DateTimeField(auto_now_add=True)),
('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')),
],
options={
'permissions': [('Can_alter_level_and_Perms', 'Allow this user to change Level, Groups and Permissions?')],
},
),
migrations.CreateModel(
name='Ads',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('url', models.CharField(max_length=256)),
('imageurl', models.ImageField(upload_to='ad/%y/%m/%d/')),
],
options={
'verbose_name_plural': 'ads',
},
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('feeling', models.SmallIntegerField(choices=[(0, 'normal'), (1, 'happy'), (2, 'wink'), (3, 'surprised'), (4, 'frustrated'), (5, 'confused'), (38, 'japan'), (39, 'lol i lied'), (69, 'adam is gay'), (70, 'I am a faggot!'), (71, 'Juice'), (72, 'Commit Suicide'), (73, 'Fresh!')], default=0)),
('body', models.TextField(null=True)),
('screenshot', models.CharField(blank=True, default='', max_length=1200, null=True)),
('drawing', models.CharField(blank=True, max_length=200, null=True)),
('spoils', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True)),
('edited', models.DateTimeField(auto_now=True)),
('befores', models.TextField(blank=True, null=True)),
('has_edit', models.BooleanField(default=False)),
('is_rm', models.BooleanField(default=False, help_text='Tick this to hide this comment')),
('status', models.SmallIntegerField(choices=[(0, 'ok'), (1, 'delete by user'), (2, 'delete by authority'), (3, 'delete by mod'), (4, 'delete by admin'), (5, 'account pruge')], default=0, help_text='Used to distinguish how a comment was removed. Our purging feature uses this to determine what comments to restore and what not to.')),
],
),
migrations.CreateModel(
name='Community',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('description', models.TextField(blank=True)),
('ico', models.ImageField(blank=True, null=True, upload_to='')),
('banner', models.ImageField(blank=True, null=True, upload_to='')),
('type', models.SmallIntegerField(choices=[(0, 'General'), (1, 'Game'), (2, 'Special'), (3, 'User Community'), (4, 'Hide')], default=0, help_text='The category the community belongs in, setting this to None will remove the community.')),
('platform', models.SmallIntegerField(choices=[(0, 'None'), (1, '3DS'), (2, 'Wii U'), (3, 'Switch'), (4, '3DS and Wii U'), (5, 'PC'), (6, 'Xbox'), (7, 'Playstation')], default=0)),
('tags', models.CharField(blank=True, choices=[('announcements', 'main announcement community'), ('changelog', 'main changelog'), ('activity', 'Activity Feed posting community'), ('general', 'General Discussion Community')], help_text='Provides special functionality for specific communities.', max_length=255, null=True)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('is_rm', models.BooleanField(default=False, help_text='Tick this on to remove the community.')),
('is_feature', models.BooleanField(default=False, help_text='Feature this community on the front page where everyone can see it.')),
('require_auth', models.BooleanField(default=False, help_text='Force your users to sign in to view this community.')),
('rank_needed_to_post', models.IntegerField(default=0, help_text='Make admin only communities.')),
('creator', models.ForeignKey(blank=True, help_text="Who owns this community? It's highly recommended to not fill this on for general communities. Keep in mind that owners can block others from using communities they own.", null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'communities',
},
),
migrations.CreateModel(
name='Conversation',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='conv_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='conv_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Poll',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('able_vote', models.BooleanField(default=True)),
('choices', models.TextField(default='[]')),
('created', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('feeling', models.SmallIntegerField(choices=[(0, 'normal'), (1, 'happy'), (2, 'wink'), (3, 'surprised'), (4, 'frustrated'), (5, 'confused'), (38, 'japan'), (39, 'lol i lied'), (69, 'adam is gay'), (70, 'I am a faggot!'), (71, 'Juice'), (72, 'Commit Suicide'), (73, 'Fresh!')], default=0)),
('body', models.TextField(null=True)),
('drawing', models.CharField(blank=True, max_length=200, null=True)),
('screenshot', models.CharField(blank=True, default='', max_length=1200, null=True)),
('video', models.CharField(blank=True, default='', max_length=256, null=True)),
('url', models.URLField(blank=True, default='', max_length=1200, null=True)),
('spoils', models.BooleanField(default=False)),
('disable_yeah', models.BooleanField(default=False)),
('lock_comments', models.SmallIntegerField(choices=[(0, 'Not locked'), (1, 'Locked by user'), (2, 'Locked by mod')], default=0, help_text='People will not be able to comment on posts that are locked.')),
('created', models.DateTimeField(auto_now_add=True)),
('edited', models.DateTimeField(auto_now=True)),
('befores', models.TextField(blank=True, help_text='If this post gets edited, the old body will be here.', null=True)),
('has_edit', models.BooleanField(default=False)),
('is_rm', models.BooleanField(default=False, help_text='Tick this to hide this post')),
('status', models.SmallIntegerField(choices=[(0, 'ok'), (1, 'delete by user'), (2, 'delete by authority'), (3, 'delete by mod'), (4, 'delete by admin'), (5, 'account pruge')], default=0, help_text='Used to distinguish how a post was removed. Our purging feature uses this to determine what posts to restore and what not to.')),
('community', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.community')),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('poll', models.ForeignKey(blank=True, help_text='A busted ass poll feature that does not work.', null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.poll')),
],
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('is_static', models.BooleanField(default=False)),
('image', models.ImageField(help_text="Upload an icon that will show on the top left of one's profile. A 22x22 image works best!", upload_to='roles/')),
('organization', models.CharField(blank=True, help_text="Text that shows above one's username", max_length=255, null=True)),
],
),
migrations.CreateModel(
name='UserRequest',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='closedverse_main.user')),
('ua', models.TextField(blank=True, default='', null=True)),
('latest', models.DateTimeField(auto_now=True)),
('status', models.SmallIntegerField(choices=[(0, 'submitted'), (1, 'viewed'), (2, 'accepted'), (3, 'decline'), (4, 'ignore')], default=0)),
],
options={
'abstract': False,
},
bases=('closedverse_main.user',),
),
migrations.CreateModel(
name='Yeah',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('type', models.SmallIntegerField(choices=[(0, 'post'), (1, 'comment')], default=0)),
('created', models.DateTimeField(auto_now_add=True)),
('by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('comment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.comment')),
('post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.post')),
],
),
migrations.CreateModel(
name='Warning',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('reason', models.TextField(blank=True, null=True)),
('by', models.ForeignKey(help_text='This is not shown to the recipient', on_delete=django.db.models.deletion.CASCADE, related_name='Warned_by', to=settings.AUTH_USER_MODEL)),
('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Warned_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='UserBlock',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='block_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='block_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='ProfileHistory',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('old_nickname', models.CharField(blank=True, max_length=64, null=True)),
('new_nickname', models.CharField(blank=True, max_length=64, null=True)),
('old_comment', models.TextField(blank=True, null=True)),
('new_comment', models.TextField(blank=True)),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'profile histories',
},
),
migrations.CreateModel(
name='Profile',
fields=[
('is_new', models.BooleanField(default=True)),
('id', models.AutoField(primary_key=True, serialize=False)),
('origin_id', models.CharField(blank=True, max_length=16, null=True)),
('origin_info', models.CharField(blank=True, max_length=255, null=True)),
('comment', models.TextField(blank=True, default='')),
('country', models.CharField(blank=True, default='', max_length=120)),
('whatareyou', models.CharField(blank=True, default='', max_length=120)),
('id_visibility', models.SmallIntegerField(choices=[(0, 'show'), (1, 'friends only'), (2, 'hide')], default=0)),
('pronoun_is', models.IntegerField(choices=[(0, 'Not specified'), (1, 'He/him'), (2, 'She/her'), (3, 'He/she'), (4, 'It'), (5, 'They/Them')], default=0, help_text='haha attack helicopter.')),
('let_friendrequest', models.SmallIntegerField(choices=[(0, 'show'), (1, 'friends only'), (2, 'hide')], default=0)),
('yeahs_visibility', models.SmallIntegerField(choices=[(0, 'show'), (1, 'friends only'), (2, 'hide')], default=0)),
('comments_visibility', models.SmallIntegerField(choices=[(0, 'show'), (1, 'friends only'), (2, 'hide')], default=2)),
('weblink', models.CharField(blank=True, default='', max_length=1200)),
('external', models.CharField(blank=True, default='', max_length=255)),
('let_yeahnotifs', models.BooleanField(default=True)),
('let_freedom', models.BooleanField(default=True, help_text='Restrict this user from posting images, videos, URLs, and even making new accounts.')),
('limit_post', models.SmallIntegerField(default=0, help_text='Great for spammers, set to "0" to remove the restriction.')),
('cannot_edit', models.BooleanField(default=False, help_text='Make it so this user cannot change settings.')),
('email_login', models.SmallIntegerField(choices=[(0, 'Do not allow'), (1, 'Okay'), (2, 'Only allow')], default=1)),
('favorite', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='closedverse_main.post')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='PollVote',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('done', models.DateTimeField(auto_now_add=True)),
('choice', models.SmallIntegerField(default=0)),
('by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.poll')),
],
),
migrations.CreateModel(
name='Notification',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('unique_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('read', models.BooleanField(default=False)),
('type', models.SmallIntegerField(choices=[(0, 'Yeah on post'), (1, 'Yeah on comment'), (2, 'Comment on my post'), (3, "Comment on others' post"), (4, 'Follow to me'), (5, 'Warning received')])),
('merges', models.TextField(blank=True, default='')),
('created', models.DateTimeField(auto_now_add=True)),
('latest', models.DateTimeField(auto_now=True)),
('context_comment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.comment')),
('context_post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.post')),
('context_warning', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.warning')),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notification_sender', to=settings.AUTH_USER_MODEL)),
('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notification_to', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='MetaViews',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('from_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='from_user', to=settings.AUTH_USER_MODEL)),
('target_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='target_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('feeling', models.SmallIntegerField(choices=[(0, 'normal'), (1, 'happy'), (2, 'wink'), (3, 'surprised'), (4, 'frustrated'), (5, 'confused'), (38, 'japan'), (39, 'lol i lied'), (69, 'adam is gay'), (70, 'I am a faggot!'), (71, 'Juice'), (72, 'Commit Suicide'), (73, 'Fresh!')], default=0)),
('body', models.TextField(null=True)),
('drawing', models.CharField(blank=True, max_length=200, null=True)),
('screenshot', models.CharField(blank=True, default='', max_length=1200, null=True)),
('url', models.URLField(blank=True, default='', max_length=1200, null=True)),
('created', models.DateTimeField(auto_now_add=True)),
('read', models.BooleanField(default=False)),
('is_rm', models.BooleanField(default=False)),
('conversation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.conversation')),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='LoginAttempt',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('success', models.BooleanField(default=False)),
('addr', models.CharField(blank=True, max_length=64, null=True)),
('user_agent', models.TextField(blank=True, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Invites',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('code', models.CharField(default=uuid.uuid4, max_length=36)),
('used', models.BooleanField(default=False)),
('void', models.BooleanField(default=False)),
('creator', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='invite_creator', to=settings.AUTH_USER_MODEL)),
('used_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='invited_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Friendship',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('latest', models.DateTimeField(auto_now=True)),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='friend_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='friend_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='FriendRequest',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('body', models.TextField(blank=True, default='', null=True)),
('read', models.BooleanField(default=False)),
('finished', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True)),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fr_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fr_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Follow',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='follow_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='follow_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='ConversationInvite',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('body', models.TextField(blank=True, default='', null=True)),
('read', models.BooleanField(default=False)),
('finished', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True)),
('conversation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.conversation')),
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='convinvite_source', to=settings.AUTH_USER_MODEL)),
('target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='convinvite_target', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Complaint',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('type', models.SmallIntegerField(choices=[(0, 'Bug report'), (1, 'Suggestion'), (2, 'Want')])),
('body', models.TextField(blank=True, default='')),
('sex', models.SmallIntegerField(choices=[(0, 'girl'), (1, 'privileged one'), (2, '(none)')], null=True)),
('created', models.DateTimeField(auto_now_add=True)),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='CommunityFavorite',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('community', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.community')),
],
),
migrations.AddField(
model_name='comment',
name='community',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.community'),
),
migrations.AddField(
model_name='comment',
name='creator',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='comment',
name='original_post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='closedverse_main.post'),
),
migrations.CreateModel(
name='Ban',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('reason', models.TextField(blank=True, null=True)),
('expiry_date', models.DateTimeField(help_text='The date and time on which this ban will expire, Set this way off into the future if this ban should be permanent')),
('active', models.BooleanField(default=True, help_text='Untick this to disable this ban')),
('ip_address', models.CharField(blank=True, help_text='Put an IP address in here to make this an IP ban. When using the ban function outside of the Django admin panel, this is filled in automatically.', max_length=256, null=True)),
('by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='banned_by', to=settings.AUTH_USER_MODEL)),
('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='banned_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='AuditLog',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True)),
('type', models.SmallIntegerField(choices=[(0, 'Post delete'), (1, 'Comment delete'), (2, 'User edit'), (3, 'Disable comments'), (4, 'Community edit'), (5, 'Ban user'), (6, 'Edit ban for user')])),
('reasoning', models.TextField(blank=True, default='', null=True)),
('by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='audit_by', to=settings.AUTH_USER_MODEL)),
('comment', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='audit_comment', to='closedverse_main.comment')),
('community', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='audit_community', to='closedverse_main.community')),
('post', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='audit_post', to='closedverse_main.post')),
('reversed_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='audit_reverse_by', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='audit_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='user',
name='role',
field=models.ForeignKey(blank=True, help_text="This will show a funny badge and text on this user's profile. This does not grant the user any additional power and is only visual.", null=True, on_delete=django.db.models.deletion.SET_NULL, to='closedverse_main.role'),
),
migrations.AddField(
model_name='user',
name='user_permissions',
field=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'),
),
]
+20 -34
View File
@@ -750,27 +750,31 @@ class Community(models.Model):
return False
def post_perm(self, request):
if not request.user.is_authenticated:
return False
if request.user.has_perm('closedverse_main.change_community') or request.user.has_perm('closedverse_main.add_post'):
# if you have editing or post perms in /admin, you can override shit.
# oh god this will become a clusterfuck of logic...
return True
if self.Community_block(request):
return False
if request.user.level >= self.rank_needed_to_post:
return True
elif request.user.is_staff == True:
return False
def can_edit_community(self, user):
# i hate how I have to include this shit
if not user.is_authenticated:
return False
if user.has_perm('closedverse_main.change_community'):
# if you have editing perms, you can edit whatever community you want.
return True
if not user.level >= self.rank_needed_to_post:
return False
if user == self.creator:
return True
if user.level >= settings.level_needed_to_man_communities and self.creator:
return True
return False
def can_edit_community(self, request):
# yanderedev moment
if not request.user.is_authenticated:
return False
# If the user is a mod but can't post in one community, the user should not edit it either.
if not request.user.level >= self.rank_needed_to_post and not request.user.is_staff == True:
return False
if request.user == self.creator:
return True
elif request.user.level >= settings.level_needed_to_man_communities or request.user.is_staff == True:
return True
else:
return False
def has_favorite(self, request):
if request.user.communityfavorite_set.filter(community=self).exists():
return True
@@ -1681,19 +1685,6 @@ class Message(models.Model):
raise ValueError
return json.dumps(ls)
class ConversationInvite(models.Model):
id = models.AutoField(primary_key=True)
conversation = models.ForeignKey(Conversation, on_delete=models.CASCADE)
source = models.ForeignKey(User, related_name='convinvite_source', on_delete=models.CASCADE)
target = models.ForeignKey(User, related_name='convinvite_target', on_delete=models.CASCADE)
body = models.TextField(blank=True, null=True, default='')
read = models.BooleanField(default=False)
finished = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "Invite to conversation " + str(self.conversation) + " from " + str(self.source) + " to " + str(self.target)
class Poll(models.Model):
id = models.AutoField(primary_key=True)
able_vote = models.BooleanField(default=True)
@@ -1815,12 +1806,6 @@ class AuditLog(models.Model):
else:
return False
class UserRequest(User):
# USER AGENT
ua = models.TextField(default='', null=True, blank=True)
latest = models.DateTimeField(auto_now=True)
status = models.SmallIntegerField(default=0, choices=((0, 'submitted'), (1, 'viewed'), (2, 'accepted'), (3, 'decline'), (4, 'ignore'), ))
class Ads(models.Model):
id = models.AutoField(primary_key=True)
created = models.DateTimeField(auto_now_add=True)
@@ -1847,6 +1832,7 @@ class Ads(models.Model):
return "Ad with id " + str(self.id) + ", created at " + str(self.created) + ", with url " + str(self.url) + ", and imageurl " + str(self.imageurl)
# thing will log changes to your bio or nickname
# i should get rid of this, its worthless.
class ProfileHistory(models.Model):
id = models.AutoField(primary_key=True)
created = models.DateTimeField(auto_now_add=True)
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>You are banned</title>
</head>
<body>
<h1>You are banned from {{ brand_name }}.</h1>
{% if ban.reason %}<p>Reason: {{ ban.reason }}</p>{% endif %}
<p>Your ban will expire on {{ ban.expiry_date }}</p>
<p>{{ ban.expiry_date|timeuntil }} remaining.</p>
</body>
</html>
@@ -1,8 +1,5 @@
{% extends "closedverse_main/layout.html" %}
{% block main-body %}{% load closedverse_user %}{% load closedverse_tags %}{% load closedverse_community %}
{% if not request.user == community.creator %}<div class='notice'>
<p>Mods and staff members can edit communities.</p>
</div>{% endif %}
{% community_sidebar community request %}
<div class="main-column"><div class="post-list-outline">
<h2 class="label">Change settings for {% if community.creator %}{{ community.creator }}'s{% else %}this{% endif %} community</h2>
@@ -5,7 +5,7 @@ register = template.Library()
def community_sidebar(community, request):
return {
'community': community,
'can_edit': community.can_edit_community(request),
'can_edit': community.can_edit_community(request.user),
'Community_block': community.Community_block(request),
'request': request,
}
+7 -13
View File
@@ -54,11 +54,7 @@ def community_list(request):
"""Lists communities / main page."""
#popularity = Community.popularity
obj = Community.objects
# if there are no featured communities, sort by popularity instead.
if not obj.filter(is_feature=True).exists():
feature = sorted(obj.filter().exclude(type=4), key=lambda x: x.popularity(), reverse=True)[0:4]
else:
feature = obj.filter(is_feature=True).order_by('-created')
feature = obj.filter(is_feature=True).order_by('-created')
if request.user.is_authenticated:
# If no profile exists for request.user, make one automatically.
profile_exists = Profile.objects.filter(user=request.user).exists()
@@ -123,7 +119,7 @@ def community_all(request, category):
category_type = category_enum[0]
communities = Community.get_all(category_type, offset)
# Closedverse was NEVER meant to have 20000000 communities.
if communities.count() > 11:
if communities.count() > 12:
has_next = True
else:
has_next = False
@@ -438,7 +434,7 @@ def user_view(request, username):
nickname_old = user.nickname
if profile.cannot_edit:
return json_response("Not allowed.")
if len(request.POST.get('screen_name')) is 0 or len(request.POST['screen_name']) > 32:
if len(request.POST.get('screen_name')) == 0 or len(request.POST['screen_name']) > 32:
return json_response('Nickname is too long or too short (length '+str(len(request.POST.get('screen_name')))+', max 32)')
if len(request.POST.get('profile_comment')) > 2200:
return json_response('Profile comment is too long (length '+str(len(request.POST.get('profile_comment')))+', max 2200)')
@@ -936,7 +932,6 @@ def community_view(request, community):
"""View an individual community"""
communities = get_object_or_404(Community, id=community)
communities.setup(request)
can_edit = communities.can_edit_community(request)
if not communities.clickable():
return HttpResponseForbidden()
if not request.user.is_authenticated and communities.require_auth:
@@ -989,10 +984,9 @@ def community_favorite_rm(request, community):
def community_tools(request, community):
the_community = get_object_or_404(Community, id=community)
activity_feed = True if the_community.type == 4 else False
if not request.user.is_authenticated:
raise Http404()
can_edit = the_community.can_edit_community(request)
can_edit = the_community.can_edit_community(request.user)
if not can_edit:
raise Http404()
form = CommunitySettingForm(instance=the_community)
@@ -1000,7 +994,6 @@ def community_tools(request, community):
'title': 'Community tools',
'form': form,
'community': the_community,
'activity_feed': activity_feed,
})
def community_tools_set(request, community):
@@ -1008,14 +1001,15 @@ def community_tools_set(request, community):
the_community = get_object_or_404(Community, id=community)
if not request.user.is_authenticated:
return HttpResponseForbidden()
can_edit = the_community.can_edit_community(request)
can_edit = the_community.can_edit_community(request.user)
if not can_edit:
return HttpResponseForbidden()
form = CommunitySettingForm(request.POST, request.FILES, instance=the_community)
if not form.is_valid():
return json_response(form.errors.as_text())
form.save()
AuditLog.objects.create(type=4, community=the_community, user=the_community.creator, by=request.user)
if not request.user == the_community.creator:
AuditLog.objects.create(type=4, community=the_community, user=the_community.creator, by=request.user)
return redirect(reverse('main:community-view', args=[the_community.id]))
else:
raise Http404()