Skip to content

Commit

Permalink
Merge branch 'main' into fix/update-django-urls-to-re_path
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslinhares authored Aug 25, 2023
2 parents d255de3 + 9ca0dab commit 021203c
Show file tree
Hide file tree
Showing 103 changed files with 4,264 additions and 173 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore=E501,F405,T003,E203,W503
81 changes: 81 additions & 0 deletions .github/workflows/build-rapidpro-apps-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and Publish Rapidpro-apps With Poetry in PyPI
on:
push:
tags:
- '*.*.*'
- '*.*.*a*'

jobs:
publish:
runs-on: ubuntu-latest

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

- name: Set variables
shell: bash
run: |
TAG="$( echo "${GITHUB_REF}" | cut -d'/' -f3 )"
VERSION="${TAG}"
echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}"
- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry self update 1.5.1
- name: Verify Poetry installation
run: poetry --version

- name: Update version in pyproject.toml
shell: bash
run: |
sed -i 's;^version *=.*$;version = "'$VERSION'";g' pyproject.toml
- name: Commit & Push changes in rapidpro-apps
if: ${{ !contains(env.VERSION, 'a') }}
uses: actions-js/push@master
with:
github_token: "${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}"
repository: weni-ai/rapidpro-apps
directory: .
branch: "refs/heads/update/${{ env.VERSION }}"
message: "Update version of weni-rp-apps to ${{ env.VERSION }}"

- name: Build package
run: poetry build

- name: Publish to pypi
shell: bash
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
- name: Checkout Flows repository
uses: actions/checkout@master
with:
ref: main
repository: weni-ai/flows
token: "${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}"
path: ./rapidpro/

- name: Update version on pip-requires.txt
run: |
VERSION="${{ env.VERSION }}"
sed -i 's;^weni-rp-apps@==.*$;weni-rp-apps@=='$VERSION';g' ./rapidpro/docker/pip-requires.txt
- name: Commit & Push changes in Flows
uses: actions-js/push@master
with:
github_token: "${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}"
repository: weni-ai/flows
directory: ./rapidpro/
branch: "refs/heads/update/weni-rp-apps-${{ env.VERSION }}"
message: "Update version of weni-rp-apps to ${{ env.VERSION }}"

7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: https://github.com/psf/black
rev: 21.12b0
rev: 23.3.0
hooks:
- id: black
args: [--line-length=119]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
105 changes: 105 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,110 @@
## [Unreleased]

## [2.7.6] - 2023-08-11
- Add parameter to remove wpp-demo objects from the queryset list

## [2.7.5] - 2023-07-18
- Add filter by status in template report

## [2.7.4] - 2023-07-17
- Report send msgs change date filter to created on

## [2.7.3] - 2023-06-29
- Changes in the view and task generate_sent_report_messages

## [2.7.2] - 2023-06-23
- Import generate_sent_report_messages

## [2.7.1] - 2023-06-23
- Report of sent messages

## [2.7.0] - 2023-06-22
- Adjust Flows app to new Project model

## [2.6.0] - 2023-06-21
- Adding list and update methods to external service viewset
- Create viewset for prompts

## [2.5.0] - 2023-06-07
- Adjust Statistic app to new Project model
- Fix error in CI

## [2.4.4] - 2023-06-02
- Change create external service to use project over org
- Add has_channel_production flag in success orgs

## [2.4.3] - 2023-05-30
- Removes the ticketer object from the queue.release() method
- Run black and flake8 in rp-apps
- Add user to release ticketer

## [2.4.2] - 2023-05-18
- Filter active orgs to return statistics

## [2.4.1] - 2023-05-17
- Add external_api channel form in channel retrieve
- Release ticketer instance before delete queue
- Optimize search filter for active contacts

## [2.4.0] - 2023-05-03
- Add Project model to internal app
- Adjust Channel app to new project model
- Adjust Org app to new project model
- Adjust Users app to new project model

## [2.3.4] - 2023-04-27
- Update permission endpoint from User permission
- Update pre-commit config

## [2.3.3] - 2023-04-20
- Removing the internal ticketer from org serializer template
- Add agent permission in get_permissions method
- Add delete endpoint in external-services

## [2.3.2] - 2023-04-14
- Update globals endpoint to filter by org

## [2.3.0] - 2023-04-06
- Add endpoint allows the generic creation of an external service

## [2.2.0] - 2023-03-30
- Add endpoint that allows creating, retrieving, destroying and listing globals

## [2.1.3] - 2023-02-17
- Adjust the org field in the channel listing return
- Fix: does not create activities when updating the channel.config at whatsapp and whatsapp-cloud

## [2.1.2] - 2023-02-03
- Fix change the has_issues field to False, when create flow

## [2.1.1] - 2022-12-28
- Fix error with magic package usage

## [2.1.0] - 2022-12-27
- Add success org retrieve endpoint
- Create an internal client for the connect REST API
- Create new Django App from recent activity
- When creating a classifier syncs it synchronously

## [2.0.1] - 2022-12-27
- Feature: Add a new endpoint thats return file from Weni Bucket
- Feature: Add is_active filter to User-Permission endpoint

## [2.0.0] - 2022-12-23
- Feature: Create endpoint for channel type

## [1.0.34] - 2022-11-18
- Feat: Create endpoint that returns success orgs

## [1.0.33] - 2022-11-17
- Fix: Remove pagination_class from internal views
- Feat: Add internal Flow endpoint
- Feat: Add internal Classifier endpoint
- Feat: Add internal Org endpoint
- Feat: Add internal Channels endpoint
- Feat: Add internal Statistic endpoint
- Feat: Add internal User and User-Permission endpoint

## [1.0.32] - 2022-11-17
- Feat: Use internal_tickter false on TemplateOrg creation

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "weni-rp-apps"
version = "1.0.32"
version = "2.4.3"
description = "Weni apps for Rapidpro Platform"
authors = ["jcbalmeida"]
license = "AGPL-3.0"
Expand Down
Empty file added weni/activities/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions weni/activities/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.apps import AppConfig


class ActivitiesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "weni.activities"

def ready(self) -> None:
from weni.activities import signals # noqa: F401
Empty file.
65 changes: 65 additions & 0 deletions weni/activities/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import celery
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver

from temba.channels.models import Channel
from temba.flows.models import Flow
from temba.triggers.models import Trigger
from temba.campaigns.models import Campaign


def create_recent_activity(instance: models.Model, created: bool):
if instance.is_active:
action = "CREATE" if created else "UPDATE"

celery.execute.send_task(
"create_recent_activity",
kwargs=dict(
action=action,
entity=instance.__class__.__name__.upper(),
entity_name=getattr(instance, "name", None),
user=instance.modified_by.email,
flow_organization=str(instance.org.uuid),
),
)


@receiver(post_save, sender=Channel)
def channel_recent_activity_signal(sender, instance: Channel, created: bool, **kwargs):
update_fields = kwargs.get("update_fields")
if instance.channel_type not in ["WA", "WAC"] or update_fields != frozenset(
{
"config",
}
):
create_recent_activity(instance, created)


@receiver(post_save, sender=Flow)
def flow_recent_activity_signal(sender, instance: Flow, created: bool, **kwargs):
update_fields = kwargs.get("update_fields")
if update_fields != frozenset(
{
"version_number",
"modified_on",
"saved_on",
"modified_by",
"metadata",
"saved_by",
"base_language",
"has_issues",
}
):
# This condition prevents two events from being sent when creating a flow
create_recent_activity(instance, created)


@receiver(post_save, sender=Trigger)
def trigger_recent_activity_signal(sender, instance: Trigger, created: bool, **kwargs):
create_recent_activity(instance, created)


@receiver(post_save, sender=Campaign)
def campaign_recent_activity_signal(sender, instance: Campaign, created: bool, **kwargs):
create_recent_activity(instance, created)
9 changes: 9 additions & 0 deletions weni/activities/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from celery import shared_task

from weni.internal.clients import ConnectInternalClient


@shared_task(name="create_recent_activity")
def create_recent_activity(action: str, entity: str, entity_name: str, user: str, flow_organization: str):
client = ConnectInternalClient()
client.create_recent_activity(action, entity, entity_name, user, flow_organization)
12 changes: 10 additions & 2 deletions weni/analytics_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
from .views import ContactAnalyticsEndpoint, FlowRunAnalyticsEndpoint

urlpatterns = [
re_path(r"^analytics/contacts/$", ContactAnalyticsEndpoint.as_view(), name="api.v2.analytics.contacts",),
re_path(r"^analytics/flow-runs/$", FlowRunAnalyticsEndpoint.as_view(), name="api.v2.analytics.flow_runs",),
re_path(
r"^analytics/contacts/$",
ContactAnalyticsEndpoint.as_view(),
name="api.v2.analytics.contacts",
),
re_path(
r"^analytics/flow-runs/$",
FlowRunAnalyticsEndpoint.as_view(),
name="api.v2.analytics.flow_runs",
),
]

urlpatterns = format_suffix_patterns(urlpatterns, allowed=["json", "api"])
15 changes: 11 additions & 4 deletions weni/analytics_api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db.models import Count, Prefetch, Q
from django.urls import reverse
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response

from temba.api.v2.views_base import BaseAPIView, ListAPIMixin
Expand Down Expand Up @@ -111,8 +110,16 @@ def get_read_explorer(cls):
"url": reverse("api.v2.analytics.contacts"),
"slug": "contacts-analytics",
"params": [
{"name": "group", "required": False, "help": "A group name or UUID to filter by. ex: Customers"},
{"name": "deleted", "required": False, "help": "Whether to return only deleted contacts. ex: false"},
{
"name": "group",
"required": False,
"help": "A group name or UUID to filter by. ex: Customers",
},
{
"name": "deleted",
"required": False,
"help": "Whether to return only deleted contacts. ex: false",
},
{
"name": "before",
"required": False,
Expand All @@ -133,7 +140,7 @@ class FlowRunAnalyticsEndpoint(BaseAPIView, ListAPIMixin):
## List Analytics Flow Runs data
A **GET** returns analytical data related to flows, containing information about the type
A **GET** returns analytical data related to flows, containing information about the type
of runs and being able to segment by date
* **flow_uuid** - A flow UUID to filter by, ex: f5901b62-ba76-4003-9c62-72fdacc1b7b7.
Expand Down
16 changes: 0 additions & 16 deletions weni/auth/backends.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import logging

import pytz
from django.conf import settings

from mozilla_django_oidc.auth import OIDCAuthenticationBackend
from temba.orgs.models import Org

LOGGER = logging.getLogger("weni_django_oidc")

Expand Down Expand Up @@ -33,18 +29,6 @@ def create_user(self, claims):

user.save()

org = Org.objects.create(
name="Temba New",
timezone=pytz.timezone("America/Sao_Paulo"),
brand=settings.DEFAULT_BRAND,
created_by=user,
modified_by=user,
)
org.administrators.add(user)

# initialize our org, but without any credits
org.initialize(branding=org.get_branding(), topup_size=0)

return user

def update_user(self, user, claims):
Expand Down
Loading

0 comments on commit 021203c

Please sign in to comment.