Skip to content

Commit

Permalink
fix: add features post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
teehamaral committed Jul 30, 2024
1 parent 376e1e5 commit 67a3eca
Show file tree
Hide file tree
Showing 10 changed files with 27,818 additions and 85 deletions.
Binary file modified mailroom_test.dump
Binary file not shown.
27,837 changes: 27,766 additions & 71 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"dependencies": {
"@greatnonprofits-nfp/flow-editor": "1.17.6",
"@greatnonprofits-nfp/flow-editor": "1.17.9",
"@greatnonprofits-nfp/temba-analytics": "1.1.1",
"@greatnonprofits-nfp/temba-components": "0.28.2",
"@tailwindcss/ui": "0.2.2",
Expand Down
11 changes: 11 additions & 0 deletions temba/channels/migrations/0137_squashed.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ class Migration(migrations.Migration):
max_length=1,
),
),
(
"answered_by",
models.CharField(
choices=[
("H", "Human"),
("M", "Machine"),
],
max_length=1,
null=True,
),
),
("external_id", models.CharField(max_length=255)),
("created_on", models.DateTimeField(default=django.utils.timezone.now)),
("modified_on", models.DateTimeField(default=django.utils.timezone.now)),
Expand Down
8 changes: 8 additions & 0 deletions temba/channels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,18 @@ class ChannelConnection(models.Model):
(ERROR_MACHINE, _("Answering Machine")), # the call went to an answering machine
)

ANSWERED_BY_HUMAN = "H"
ANSWERED_BY_MACHINE = "M"
ANSWERED_BY_CHOICES = (
(ANSWERED_BY_HUMAN, _("Human")),
(ANSWERED_BY_MACHINE, _("Machine")),
)

org = models.ForeignKey(Org, on_delete=models.PROTECT)
connection_type = models.CharField(max_length=1, choices=TYPE_CHOICES)
direction = models.CharField(max_length=1, choices=DIRECTION_CHOICES)
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
answered_by = models.CharField(max_length=1, choices=ANSWERED_BY_CHOICES, null=True)

channel = models.ForeignKey("Channel", on_delete=models.PROTECT, related_name="connections")
contact = models.ForeignKey("contacts.Contact", on_delete=models.PROTECT, related_name="connections")
Expand Down
2 changes: 1 addition & 1 deletion temba/flows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ def get(self, request, *args, **kwargs):
if active_editor is not None:
if self.request.user.username == active_editor.decode():
editing_available = True
r.expire(flow_key, 60)
r.expire(flow_key, 300)
else:
reader_session = True
session_expired = False if reader_session else not editing_available
Expand Down
21 changes: 20 additions & 1 deletion temba/orgs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5056,6 +5056,14 @@ def form_valid(self, form):

class OptOutMessage(InferOrgMixin, OrgPermsMixin, SmartUpdateView):
class OptOutMessageForm(forms.ModelForm):
disable_opt_out = forms.BooleanField(
required=False,
label=_("Disable opt-out"),
widget=CheckboxWidget(),
help_text=_("Soft opt-out opts users out for negative messages like swear words."),
initial=False,
)

message = forms.CharField(
required=False,
label=_("Message"),
Expand All @@ -5075,7 +5083,7 @@ def __init__(self, *args, **kwargs):

class Meta:
model = Org
fields = ("message",)
fields = ("message", "disable_opt_out")

success_message = ""
form_class = OptOutMessageForm
Expand All @@ -5084,6 +5092,7 @@ def derive_initial(self):
initial = super().derive_initial()
org = self.derive_org()
initial["message"] = (org.config or {}).get("opt_out_message_back")
initial["disable_opt_out"] = (org.config or {}).get("opt_out_disabled")
return initial

def get_form_kwargs(self):
Expand All @@ -5094,13 +5103,23 @@ def get_form_kwargs(self):
def form_valid(self, form):
org = self.request.user.get_org()
current_config = org.config or {}

if form.cleaned_data.get("message"):
current_config.update(dict(opt_out_message_back=form.cleaned_data.get("message")))
else:
try:
current_config.pop("opt_out_message_back")
except KeyError:
pass

if form.cleaned_data.get("disable_opt_out"):
current_config.update(dict(opt_out_disabled=True))
else:
try:
current_config.pop("opt_out_disabled")
except KeyError:
pass

org.config = current_config
org.save(update_fields=["config"])
return super().form_valid(form)
Expand Down
1 change: 0 additions & 1 deletion temba/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@
"orgs.org_import",
"orgs.org_lookups",
"orgs.org_menu",
"orgs.org_opt_out_message",
"orgs.org_parse_data_view",
"orgs.org_parse_data_import",
"orgs.org_profile",
Expand Down
18 changes: 9 additions & 9 deletions temba/utils/management/commands/mailroom_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def handle(self, *args, **kwargs):

self._log("Checking Postgres database version... ")

result = subprocess.run(["pg_dump", "--version"], stdout=subprocess.PIPE)
result = subprocess.run(["/Applications/Postgres.app/Contents/Versions/15/bin/pg_dump", "--version"], stdout=subprocess.PIPE)
version = result.stdout.decode("utf8")
if version.split(" ")[-1].find("12.") == 0:
if version.split(" ")[-1].find("15.") == 0:
self._log(self.style.SUCCESS("OK") + "\n")
else:
self._log(
Expand All @@ -69,11 +69,11 @@ def handle(self, *args, **kwargs):
self._log("Initializing mailroom_test database...\n")

# drop and recreate the mailroom_test db and user
subprocess.check_call('psql -c "DROP DATABASE IF EXISTS mailroom_test;"', shell=True)
subprocess.check_call('psql -c "CREATE DATABASE mailroom_test;"', shell=True)
subprocess.check_call('psql -c "DROP USER IF EXISTS mailroom_test;"', shell=True)
subprocess.check_call("psql -c \"CREATE USER mailroom_test PASSWORD 'temba';\"", shell=True)
subprocess.check_call('psql -c "ALTER ROLE mailroom_test WITH SUPERUSER;"', shell=True)
subprocess.check_call('/Applications/Postgres.app/Contents/Versions/15/bin/psql -c "DROP DATABASE IF EXISTS mailroom_test;"', shell=True)
subprocess.check_call('/Applications/Postgres.app/Contents/Versions/15/bin/psql -c "CREATE DATABASE mailroom_test;"', shell=True)
subprocess.check_call('/Applications/Postgres.app/Contents/Versions/15/bin/psql -c "DROP USER IF EXISTS mailroom_test;"', shell=True)
subprocess.check_call("/Applications/Postgres.app/Contents/Versions/15/bin/psql -c \"CREATE USER mailroom_test PASSWORD 'temba';\"", shell=True)
subprocess.check_call('/Applications/Postgres.app/Contents/Versions/15/bin/psql -c "ALTER ROLE mailroom_test WITH SUPERUSER;"', shell=True)

# always use mailroom_test as our db
settings.DATABASES["default"]["NAME"] = "mailroom_test"
Expand Down Expand Up @@ -112,7 +112,7 @@ def handle(self, *args, **kwargs):
self.reset_id_sequences(30000)

# dump our file
subprocess.check_call("pg_dump -Fc mailroom_test > mailroom_test.dump", shell=True)
subprocess.check_call("/Applications/Postgres.app/Contents/Versions/15/bin/pg_dump -Fc mailroom_test > mailroom_test.dump", shell=True)

self._log("\n" + self.style.SUCCESS("Success!") + " Dump file: mailroom_test.dump\n\n")

Expand All @@ -126,7 +126,7 @@ def load_locations(self, path):
db_config = settings.DATABASES["default"]
try:
subprocess.check_call(
f"export PGPASSWORD={db_config['PASSWORD']} && pg_restore -h {db_config['HOST']} "
f"export PGPASSWORD={db_config['PASSWORD']} && /Applications/Postgres.app/Contents/Versions/15/bin/pg_restore -h {db_config['HOST']} "
f"-p {db_config['PORT']} -U {db_config['USER']} -w -d {db_config['NAME']} {path}",
shell=True,
)
Expand Down
3 changes: 2 additions & 1 deletion templates/orgs/org_opt_out_message.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@


-block fields
-render_field "message"
-render_field "message"
-render_field "disable_opt_out"

0 comments on commit 67a3eca

Please sign in to comment.