-
Notifications
You must be signed in to change notification settings - Fork 41
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 #1856 from gtech-mulearn:dev
[FEAT] Bulk role API updates
- Loading branch information
Showing
14 changed files
with
850 additions
and
498 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import sys | ||
import uuid | ||
from decouple import config | ||
import django | ||
|
||
from connection import execute | ||
|
||
os.chdir('..') | ||
sys.path.append(os.getcwd()) | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mulearnbackend.settings') | ||
django.setup() | ||
|
||
from utils.utils import DiscordWebhooks | ||
from utils.types import WebHookActions, WebHookCategory | ||
|
||
def is_role_exist(title): | ||
query = f"SELECT id FROM role WHERE title = '{title}'" | ||
return True if execute(query) else False | ||
|
||
def get_intrest_groups(): | ||
query = f"SELECT name,code, created_by FROM interest_group" | ||
return execute(query) | ||
|
||
def create_ig_lead_roles(): | ||
for name,code,created_by in get_intrest_groups(): | ||
role_name = f"{code} CampusLead" | ||
if not is_role_exist(role_name): | ||
query = f"""INSERT INTO role (id, title, description ,created_by, updated_by,updated_at,created_at) | ||
VALUES ( | ||
'{uuid.uuid4()}', | ||
'{role_name}', | ||
'{f'Campus Lead of {name} Interest Group'}', | ||
'{created_by}', | ||
'{created_by}', | ||
UTC_TIMESTAMP, | ||
UTC_TIMESTAMP | ||
) | ||
""" | ||
execute(query) | ||
DiscordWebhooks.general_updates( | ||
WebHookCategory.ROLE.value, | ||
WebHookActions.CREATE.value, | ||
role_name | ||
) | ||
role_name = f'{code} IGLead' | ||
if not is_role_exist(role_name): | ||
query = f"""INSERT INTO role (id, title, description ,created_by, updated_by,updated_at,created_at) | ||
VALUES ( | ||
'{uuid.uuid4()}', | ||
'{role_name}', | ||
'{f'Interest Group Lead of {name} Interest Group'}', | ||
'{created_by}', | ||
'{created_by}', | ||
UTC_TIMESTAMP, | ||
UTC_TIMESTAMP | ||
) | ||
""" | ||
execute(query) | ||
DiscordWebhooks.general_updates( | ||
WebHookCategory.ROLE.value, | ||
WebHookActions.CREATE.value, | ||
role_name | ||
) | ||
|
||
if __name__ == '__main__': | ||
create_ig_lead_roles() | ||
execute("UPDATE system_setting SET value = '1.46', updated_at = now() WHERE `key` = 'db.version';") | ||
|
Empty file.
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.