Skip to content

Commit

Permalink
Merge branch 'main' into 12ka4
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagyashree980 authored Jan 21, 2025
2 parents 1fc049b + 309bceb commit cc49899
Show file tree
Hide file tree
Showing 95 changed files with 2,190 additions and 1,598 deletions.
26 changes: 21 additions & 5 deletions .github/ansible/production/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
state: directory
mode: '0755'

- name: Copy Nginx configuration file
- name: Copy nginx configuration file
ansible.builtin.copy:
src: '{{ github_workspace }}/nginx/production.conf'
dest: ~/nginx/nginx.conf
Expand All @@ -25,29 +25,45 @@
state: directory
mode: '0755'

- name: Copy Backend Makefile
- name: Copy backend makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/backend/Makefile'
dest: ~/backend/Makefile
mode: '0644'

- name: Update Makefile for the production environment
- name: Update backend makefile for the production environment
shell:
cmd: "sed -i 's/\\bnest-backend\\b/production-nest-backend/' ~/backend/Makefile"

- name: Ensure cspell directory exists
ansible.builtin.file:
path: ~/cspell
state: directory
mode: '0755'

- name: Copy cspell makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/cspell/Makefile'
dest: ~/cspell/Makefile
mode: '0644'

- name: Ensure frontend directory exists
ansible.builtin.file:
path: ~/frontend
state: directory
mode: '0755'

- name: Copy Frontend Makefile
- name: Copy frontend makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/frontend/Makefile'
dest: ~/frontend/Makefile
mode: '0644'

- name: Copy Makefile
- name: Update frontend makefile for the production environment
shell:
cmd: "sed -i 's/\\bnest-frontend\\b/production-nest-frontend/' ~/frontend/Makefile"

- name: Copy main makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/Makefile'
dest: ~/Makefile
Expand Down
28 changes: 22 additions & 6 deletions .github/ansible/staging/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
state: directory
mode: '0755'

- name: Copy Nginx configuration file
- name: Copy nginx configuration file
ansible.builtin.copy:
src: '{{ github_workspace }}/nginx/staging.conf'
dest: ~/nginx/nginx.conf
Expand All @@ -25,29 +25,45 @@
state: directory
mode: '0755'

- name: Copy Backend Makefile
- name: Copy backend Makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/backend/Makefile'
dest: ~/backend/Makefile
mode: '0644'

- name: Update Makefile for the staging environment
- name: Update backend makefile for the staging environment
shell:
cmd: "sed -i 's/\\bnest-backend\\b/staging-nest-backend/' ~/backend/Makefile"

- name: Ensure backend directory exists
- name: Ensure cspell directory exists
ansible.builtin.file:
path: ~/cspell
state: directory
mode: '0755'

- name: Copy cspell makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/cspell/Makefile'
dest: ~/cspell/Makefile
mode: '0644'

- name: Ensure frontend directory exists
ansible.builtin.file:
path: ~/frontend
state: directory
mode: '0755'

- name: Copy Frontend Makefile
- name: Copy frontend makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/frontend/Makefile'
dest: ~/frontend/Makefile
mode: '0644'

- name: Copy Makefile
- name: Update frontend makefile for the staging environment
shell:
cmd: "sed -i 's/\\bnest-frontend\\b/staging-nest-frontend/' ~/frontend/Makefile"

- name: Copy main makefile
ansible.builtin.copy:
src: '{{ github_workspace }}/Makefile'
dest: ~/Makefile
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__
.mypy_cache
.pytest_cache
.python_history
.python-version
.ruff_cache
.vscode
*.code-workspace
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ If you plan to fetch GitHub OWASP data locally, follow these additional steps:

#### NestBot Development

:exclamation: **Never install your development Slack application in the OWASP Slack workspace.
:exclamation: Doing so will interfere with OWASP Nest functionality and trigger unnecessary notifications to Slack admins.
:exclamation: Always use a different workspace (create your own if needed).**

To setup NestBot development environment, follow these steps:

1. **Set Up ngrok**:
Expand Down Expand Up @@ -289,6 +293,18 @@ git checkout -b feature/my-feature-name
- Address feedback from maintainers during code review.
- Once approved, your PR will be merged into the main branch.
## Troubleshooting
- **"Unexpected character" error during application execution or Docker image building**
This error is usually caused by incorrect encoding of `.env` files.
- Open the `.env` files in a text editor (e.g., VS Code) and save them as "UTF-8 without BOM."
- Restart the application with `make run` and verify the error is resolved.
Tips:
- Ensure consistent file encoding using a code editor or linter.
- If the issue persists, check the project's documentation or issue tracker.

## Code of Conduct

Please follow the [Code of Conduct](https://github.com/OWASP/Nest/blob/main/CODE_OF_CONDUCT.md) when interacting with other contributors.
Expand Down
161 changes: 57 additions & 104 deletions backend/apps/slack/actions/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,128 +4,71 @@

from slack_sdk.errors import SlackApiError

from apps.common.constants import NL
from apps.common.utils import truncate
from apps.slack.apps import SlackConfig
from apps.slack.blocks import get_header
from apps.slack.blocks import get_header, markdown
from apps.slack.common.handlers import chapters, committees, projects
from apps.slack.common.presentation import EntityPresentation
from apps.slack.constants import (
VIEW_CHAPTERS_ACTION,
VIEW_CHAPTERS_ACTION_NEXT,
VIEW_CHAPTERS_ACTION_PREV,
VIEW_COMMITTEES_ACTION,
VIEW_COMMITTEES_ACTION_NEXT,
VIEW_COMMITTEES_ACTION_PREV,
VIEW_PROJECTS_ACTION,
VIEW_PROJECTS_ACTION_NEXT,
VIEW_PROJECTS_ACTION_PREV,
)

logger = logging.getLogger(__name__)


def handle_home_actions(ack, body, client):
"""Handle actions triggered for Projects, Committees, and Chapters."""
from apps.owasp.api.search.chapter import get_chapters
from apps.owasp.api.search.committee import get_committees
from apps.owasp.api.search.project import get_projects

"""Handle actions triggered in the home view."""
ack()

action_id = body["actions"][0]["action_id"]
user_id = body["user"]["id"]
payload = body.get("actions", [])[0]
value = payload.get("value", "1")

try:
home_presentation = EntityPresentation(
include_feedback=False,
include_metadata=True,
include_pagination=True,
include_timestamps=False,
name_truncation=80,
summary_truncation=200,
)

page = int(value) if value.isdigit() else 1

blocks = []

match action_id:
case "view_projects_action":
details = get_projects(query="", limit=10, page=1)
blocks = (
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": (
f"*<{project['idx_url']}|{idx}. {project['idx_name']}>*{NL}"
f"Contributors: {project['idx_contributors_count']} | "
f"Forks: {project['idx_forks_count']} | "
f"Stars: {project['idx_stars_count']}{NL}"
f"{truncate(project['idx_summary'], 300)}"
),
},
}
for idx, project in enumerate(details["hits"], 1)
]
if details["hits"]
else [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "No projects found based on your search query.",
},
}
]
)

case "view_committees_action":
details = get_committees(query="", limit=10, page=1)
blocks = (
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": (
f"*<{committee['idx_url']}|{idx}. {committee['idx_name']}>*\n"
f"{truncate(committee['idx_summary'], 300)}{NL}"
),
},
}
for idx, committee in enumerate(details["hits"], 1)
]
if details["hits"]
else [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "No committees found based on your search query.",
},
}
]
)

case "view_chapters_action":
details = get_chapters(query="", limit=10, page=1)
blocks = (
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": (
f"*<{chapter['idx_url']}|{idx}. {chapter['idx_name']}>*\n"
f"{truncate(chapter['idx_summary'], 300)}{NL}"
),
},
}
for idx, chapter in enumerate(details["hits"], 1)
]
if details["hits"]
else [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "No chapters found based on your search query.",
},
}
]
)

case action if action in {
VIEW_CHAPTERS_ACTION,
VIEW_CHAPTERS_ACTION_PREV,
VIEW_CHAPTERS_ACTION_NEXT,
}:
blocks = chapters.get_blocks(page=page, limit=10, presentation=home_presentation)

case action if action in {
VIEW_COMMITTEES_ACTION,
VIEW_COMMITTEES_ACTION_PREV,
VIEW_COMMITTEES_ACTION_NEXT,
}:
blocks = committees.get_blocks(page=page, limit=10, presentation=home_presentation)

case action if action in {
VIEW_PROJECTS_ACTION,
VIEW_PROJECTS_ACTION_PREV,
VIEW_PROJECTS_ACTION_NEXT,
}:
blocks = projects.get_blocks(page=page, limit=10, presentation=home_presentation)
case _:
blocks.append(
{
"type": "section",
"text": {"type": "mrkdwn", "text": "Invalid action, please try again."},
}
)
blocks = [markdown("Invalid action, please try again.")]

new_home_view = {
"type": "home",
Expand All @@ -143,6 +86,16 @@ def handle_home_actions(ack, body, client):

# Register the actions
if SlackConfig.app:
SlackConfig.app.action(VIEW_PROJECTS_ACTION)(handle_home_actions)
SlackConfig.app.action(VIEW_COMMITTEES_ACTION)(handle_home_actions)
SlackConfig.app.action(VIEW_CHAPTERS_ACTION)(handle_home_actions)
actions = (
VIEW_CHAPTERS_ACTION_NEXT,
VIEW_CHAPTERS_ACTION_PREV,
VIEW_CHAPTERS_ACTION,
VIEW_COMMITTEES_ACTION_NEXT,
VIEW_COMMITTEES_ACTION_PREV,
VIEW_COMMITTEES_ACTION,
VIEW_PROJECTS_ACTION_NEXT,
VIEW_PROJECTS_ACTION_PREV,
VIEW_PROJECTS_ACTION,
)
for action in actions:
SlackConfig.app.action(action)(handle_home_actions)
1 change: 1 addition & 0 deletions backend/apps/slack/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SlackConfig(AppConfig):

app = (
App(
request_verification_enabled=False,
signing_secret=settings.SLACK_SIGNING_SECRET,
token=settings.SLACK_BOT_TOKEN,
)
Expand Down
29 changes: 29 additions & 0 deletions backend/apps/slack/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ def get_header():
],
},
]


def get_pagination_buttons(entity_type, page, total_pages):
"""Get pagination buttons for the blocks."""
pagination_buttons = []

if page > 1:
pagination_buttons.append(
{
"type": "button",
"text": {"type": "plain_text", "text": "Previous"},
"action_id": f"view_{entity_type}_action_prev",
"value": str(page - 1),
"style": "primary",
}
)

if total_pages > page:
pagination_buttons.append(
{
"type": "button",
"text": {"type": "plain_text", "text": "Next"},
"action_id": f"view_{entity_type}_action_next",
"value": str(page + 1),
"style": "primary",
}
)

return pagination_buttons
Loading

0 comments on commit cc49899

Please sign in to comment.