Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User registration, with admin/user pannel #6

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
59 changes: 59 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "CodeQL"

on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Find languages
id: findLanguages
run: |
countTS=$(find ./ -type f -name '*.ts' | wc -l)
countJS=$(find ./ -type f -name '*.js' | wc -l)
countPY=$(find ./ -type f -name '*.py' | wc -l)
countCPP=$(find ./ -type f -name '*.cpp' | wc -l)
countJAVA=$(find ./ -type f -name '*.java' | wc -l)
languages=""
if [ $countTS -gt 0 ]; then
languages+="typescript,"
fi
if [ $countJS -gt 0 ]; then
languages+="javascript,"
fi
if [ $countPY -gt 0 ]; then
languages+="python,"
fi
if [ $countCPP -gt 0 ]; then
languages+="cpp,"
fi
if [ $countJAVA -gt 0 ]; then
languages+="java,"
fi
# Remove the trailing comma
languages=${languages%,}
echo "languages=$languages" >> $GITHUB_ENV

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ env.languages }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv/
data/
dev-docs/node_modules/
dev-docs/.vitepress/dist/
dev-docs/.vitepress/cache/
user-docs/node_modules/
user-docs/.vitepress/dist/
user-docs/.vitepress/cache/
**/.pytest_cache/
dist/
db.sqlite3
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### VISIT dev-docs at: https://uci-integration.vercel.app

**Project Details**

Project entails the seamless integration of cQube with Unified Communication Interface (UCI) services, ensuring businesses receive real-time notifications tailored to their preferences. The implementation includes the development of a foundational Message Generation system with threshold checks and efficient message queue handling. Additionally, a Message Routing Service is being crafted to optimize communication by intelligently routing messages according to predefined topics and recipients. Concurrently, the project involves the setup and deployment of the UCI service within cQube, providing businesses with a robust communication framework. Moreover, a User Registration System is being implemented, allowing users to subscribe to topics with personalized preferences and tracking essential statistics for enhanced insights.
Expand All @@ -10,5 +12,5 @@ To set up the project on a system, follow these guidelines:
- Fork the project
- Clone the forked project repository from GitHub.
- Set up the environment variables and configurations required to run the utility.

For more details, go through https://github.com/Code4GovTech/C4GT
Empty file added authentication/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions authentication/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions authentication/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthenticationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'authentication'
56 changes: 56 additions & 0 deletions authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.9 on 2024-01-25 09:36

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('org', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('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=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, 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')),
('org', models.CharField(max_length=255)),
('position', models.CharField(max_length=255)),
('preferences', models.CharField(max_length=255)),
('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')),
('subscription', models.ManyToManyField(to='authentication.subscription')),
('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={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
18 changes: 18 additions & 0 deletions authentication/migrations/0002_user_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-25 12:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authentication', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='user',
name='type',
field=models.CharField(choices=[('admin', 'Admin'), ('user', 'User')], default='user', max_length=255),
),
]
25 changes: 25 additions & 0 deletions authentication/migrations/0003_alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.9 on 2024-02-07 11:04

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('authentication', '0002_user_type'),
]

operations = [
migrations.CreateModel(
name='Alert',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message', models.TextField()),
('date', models.DateField()),
('subscription', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='authentication.subscription')),
('users', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.9 on 2024-02-10 09:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('authentication', '0003_alert'),
]

operations = [
migrations.RemoveField(
model_name='user',
name='org',
),
migrations.RemoveField(
model_name='user',
name='position',
),
]
Empty file.
45 changes: 45 additions & 0 deletions authentication/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

class Subscription(models.Model):
"""
Represents Subscription in the system.

Attributes:
name (CharField): The name of the subscription.
org (CharField): The organization the subscription belongs to.
"""
name = models.CharField(max_length=255)
org = models.CharField(max_length=255)

class Alert(models.Model):
"""
Represents a user in the system.

Attributes:
subscription (ForeignKey): The user's subscriptions.
message (TextField): The message of the alert.
date (DateField): The date of the alert.
users (ManyToManyField): The users who received the alert.
"""
subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE)
message = models.TextField()
date = models.DateField()
users = models.ManyToManyField('User')

class User(AbstractUser):
"""
Represents a user in the system.

Attributes:
subscription (ManyToManyField): The user's subscriptions.
# org (CharField): The organization the user belongs to.
type (CharField): The type of user (admin or user).
# position (CharField): The user's position in the organization.
preferences (CharField): The user's preferences.
"""
subscription = models.ManyToManyField(Subscription)
# org = models.CharField(max_length=255)
type = models.CharField(max_length=255, choices=[('admin', 'Admin'), ('user', 'User')], default='user')
# position = models.CharField(max_length=255)
preferences = models.CharField(max_length=255)
80 changes: 80 additions & 0 deletions authentication/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from django.test import TestCase, Client
from django.urls import reverse
from django.contrib.auth import get_user_model
from .models import Subscription, Alert

User = get_user_model()

class AuthenticationViewsTestCase(TestCase):
def setUp(self):
# Create a test user
self.user = User.objects.create_user(username='testuser', password='password')

# Create a test subscription
self.subscription = Subscription.objects.create(name='Test Subscription', org='Test Org')

# Login the test user
self.client = Client()
self.client.login(username='testuser', password='password')

def test_home_view_authenticated_user(self):
# Test home view for authenticated user
response = self.client.get(reverse('home'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'authentication/userDashboard.html')

def test_home_view_unauthenticated_user(self):
# Test home view for unauthenticated user
self.client.logout()
response = self.client.get(reverse('home'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'authentication/index.html')

def test_signup_view(self):
# Test signup view
response = self.client.post(reverse('signup'), {
'userName': 'newuser',
'firstName': 'New',
'lastName': 'User',
'email': '[email protected]',
'password': 'newpassword',
'confirmPassword': 'newpassword',
'userType': 'user'
})
self.assertEqual(response.status_code, 302) # Redirects to signin page upon successful signup

def test_signin_view(self):
# Test signin view
response = self.client.post(reverse('signin'), {
'userName': 'testuser',
'password': 'password'
})
self.assertEqual(response.status_code, 200)

def test_signout_view(self):
# Test signout view
response = self.client.get(reverse('signout'))
self.assertEqual(response.status_code, 302)

def test_addPreference_view(self):
# Test addPreference view
response = self.client.post(reverse('addPreference'), {
'preference': 'Test Preference'
})
self.assertEqual(response.status_code, 302)

def test_addSubscription_view(self):
# Test addSubscription view
response = self.client.post(reverse('addSubscription'), {
'subscription_id': self.subscription.id
})
self.assertEqual(response.status_code, 302)

def test_createSubscription_view(self):
# Test createSubscription view
response = self.client.post(reverse('createSubscription'), {
'subscriptionName': 'TestSubscription',
'orgName': 'Test Org'
})
self.assertEqual(response.status_code, 302)

16 changes: 16 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.contrib import admin
from django.urls import path, include
from . import views

urlpatterns = [
path('', views.home, name='home'),
path('signup/', views.signup, name='signup'),
path('signin/', views.signin, name='signin'),
path('signout/', views.signout, name='signout'),
path('addPreference/', views.addPreference, name='addPreference'),
path('addSubscription/', views.addSubscription, name='addSubscription'),
path('createSubscription/', views.createSubscription, name='createSubscription'),
path('editSubscription/<int:subscription_id>/', views.editSubscription, name='editSubscription'),
path('deleteSubscription/<int:subscription_id>/', views.deleteSubscription, name='deleteSubscription'),
path('sendMessage/<int:subscription_id>/', views.sendMessage, name='sendMessage'),
]
Loading