Skip to content

Commit

Permalink
config will not look for hostname-sql and similar objects unless the …
Browse files Browse the repository at this point in the history
…CONTAINERROLE is something other than all; item grid field modifier; developer can install Configuration directive; debug startup process Configuration directive; current_section attribute of output of user_info(); changed CSS so that spaces are preserved in code; fixed Sync and Run timing issue; fixed issue with datatype range UI not being disabled along with underlying input element; zipped packages were assumed to contain a root directory; datatype checkboxes variable passed as field to validation_error will be converted to a particular checkbox field; fixed the user/owner password system; support for Zitadel OAuth2 login; most social login methods did not correctly return first name and last name fields; under text field modifier
  • Loading branch information
jhpyle committed Nov 27, 2023
1 parent 9b13f84 commit 6347fa5
Show file tree
Hide file tree
Showing 62 changed files with 1,153 additions and 470 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Change Log

## [1.4.86] - 2023-11-26

### Added
- The `disabled` field modifier for showing a field on the screen that
is always disabled.
- The `under text` field modifier for showing help text under a form
field in a smaller font.
- The `item grid` field modifier, which is similar to the `grid`
modifier, but affects whether the choices in a list of radio buttons
or checkboxes wrap.
- The `developer can install` Configuration directive.
- The `debug startup process` Configuration directive for logging the
timing of the different parts of the `uwsgi` loading process.
- The `current_section` attribute of the output of `user_info()`.
- The `owner password` option under `attachment` for protecting a PDF
file with an owner password.
- Support for login using Zitadel.

### Changed
- The CSS for `<code>` elements no longer collapses spaces.

### Fixed
- The UI of fields with `datatype: range` were not shown as disabled
even if the underlying `<input>` was disabled.
- Sync and Run did not work correctly in some browsers because of a
JavaScript timing issue.
- Module files in zipped packages were not detected unless a root
directory was used.

## [1.4.85] - 2023-11-02

### Added
Expand Down
18 changes: 17 additions & 1 deletion docassemble_base/docassemble/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import socket
import threading
import time
import base64
import json
import importlib.metadata
Expand All @@ -16,6 +17,7 @@
import docassemble.base.microsoft
from docassemble.base.generate_key import random_string

START_TIME = time.time()
dbtableprefix = None
daconfig = {}
s3_config = {}
Expand All @@ -31,6 +33,7 @@
errors = []
env_messages = []
allowed = {}
DEBUG_BOOT = False


def env_true_false(var):
Expand Down Expand Up @@ -252,6 +255,7 @@ def load(**kwargs):
global GC_ENABLED
global azure_config
global AZURE_ENABLED
global DEBUG_BOOT
global dbtableprefix
global hostname
global loaded
Expand All @@ -260,6 +264,8 @@ def load(**kwargs):
global env_messages
# changed = False
filename = None
container_role = os.environ.get('CONTAINERROLE', None) or ':all:'
single_server = ':all:' in container_role
if 'arguments' in kwargs and isinstance(kwargs['arguments'], list) and len(kwargs['arguments']) > 1:
for arg in kwargs['arguments'][1:]:
if arg.startswith('--'):
Expand Down Expand Up @@ -377,6 +383,8 @@ def load(**kwargs):
daconfig['grid classes']['field grid number'] = 8
if not daconfig['grid classes'].get('grid breakpoint', None):
daconfig['grid classes']['grid breakpoint'] = 'md'
if not daconfig['grid classes'].get('item grid breakpoint', None):
daconfig['grid classes']['item grid breakpoint'] = 'md'
if not daconfig['grid classes']['vertical navigation'].get('bar', None):
daconfig['grid classes']['vertical navigation']['bar'] = 'offset-xl-1 col-xl-2 col-lg-3 col-md-3'
if not daconfig['grid classes']['vertical navigation'].get('body', None):
Expand Down Expand Up @@ -494,6 +502,8 @@ def load(**kwargs):
daconfig = cloud.load_with_secrets(daconfig)
else:
cloud = None
if 'debug startup process' in daconfig and daconfig['debug startup process']:
DEBUG_BOOT = True
if 'supervisor' in daconfig:
if not (isinstance(daconfig['supervisor'], dict) and daconfig['supervisor'].get('username', None) and daconfig['supervisor'].get('password', None)):
daconfig['supervisor'] = {}
Expand Down Expand Up @@ -683,7 +693,7 @@ def load(**kwargs):
dbtableprefix = daconfig['db'].get('table prefix', None)
if not dbtableprefix:
dbtableprefix = ''
if cloud is not None:
if cloud is not None and not single_server:
if 'host' not in daconfig['db'] or daconfig['db']['host'] is None:
key = cloud.get_key('hostname-sql')
if key.does_exist:
Expand Down Expand Up @@ -1077,6 +1087,8 @@ def load(**kwargs):
if env_exists('GOTENBERGURL'):
override_config(daconfig, messages, 'gotenberg url', 'GOTENBERGURL')
env_messages = messages
if DEBUG_BOOT:
boot_log("config: load complete")


def default_config():
Expand Down Expand Up @@ -1175,3 +1187,7 @@ def noquote(string):
if isinstance(string, str):
return string.replace('\n', ' ').replace('"', '&quot;').strip()
return string


def boot_log(message):
sys.stderr.write('%.3fs %s\n' % (time.time() - START_TIME, message))
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metadata:
title: Disabled field
documentation: "https://docassemble.org/docs/fields.html#disabled"
example start: 1
example end: 2
---
question: |
What is your favorite vegetable?
fields:
- Vegetable: favorite_vegetable
---
question: |
What are your favorite things to eat?
fields:
- Fruit: favorite_fruit
- Vegetable: favorite_vegetable_placeholder
disabled: True
default: |
${ favorite_vegetable }
---
question: Result of question
subquestion: |
Your favorite fruit is ${ favorite_fruit }.
Your favorite vegetable is ${ favorite_vegetable }.
Note that the variable
`favorite_vegetable_placeholder` is not defined.
mandatory: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
metadata:
title: Disabled field
documentation: "https://docassemble.org/docs/fields.html#disabled"
---
question: |
What are your favorite things to eat?
subquestion: |
(It goes without saying that you love turnips.)
fields:
- Fruit: favorite_fruit
- Vegetable: favorite_vegetable
disabled: True
default: turnips
---
question: Result of question
subquestion: |
Your favorite fruit is ${ favorite_fruit }.
The `favorite_vegetable` variable
was not defined by the previous
question because the field was
disabled.
mandatory: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
metadata:
title: Multiple choice items in a grid
short title: Item grid
documentation: "https://docassemble.org/docs/fields.html#item grid"
example start: 2
example end: 2
---
features:
labels above fields: True
---
question: |
Select your favorite number.
fields:
- Favorite fruit: favorite_number
item grid:
width: 3
breakpoint: sm
choices:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
---
mandatory: True
question: |
Your favorite number is ${ favorite_number }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
metadata:
title: Multiple choice items in a grid
short title: Item grid
documentation: "https://docassemble.org/docs/fields.html#item grid"
example start: 2
example end: 2
---
features:
labels above fields: True
---
question: |
Select your favorite fruit.
fields:
- Favorite fruit: favorite_fruit
item grid: 6
choices:
- Apple
- Orange
- Peach
- Pear
- Banana
- Grapes
---
mandatory: True
question: |
Your favorite fruit is ${ favorite_fruit }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
metadata:
title: JSON response
short title: JSON
documentation: "https://docassemble.org/docs/functions.html#json_response"
example start: 1
example end: 2
---
mandatory: True
question: |
Tell me about your shipment.
fields:
- Weight (lbs): weight
datatype: number
- Size: size
choices:
- Small box: 1
- Medium box: 2
- Large box: 3
- html: |
<button id="calcButton" class="btn btn-info float-end" type="button">Calculate</button>
<span id="calcResults"></span>
script: |
<script>
$("#calcButton").on('click', function(){
var theWeight = parseFloat(val('weight'))
var theSize = parseInt(val('size'))
if (theWeight && theSize){
action_call('calc', {weight: theWeight, size: theSize}, function(data){
$("#calcResults").html("That will cost $" + data.cost.toLocaleString('en-US') + ".");
});
}
})
</script>
---
event: calc
code: |
json_response({'cost': 4.44 + action_argument('weight') * 5.2 + action_argument('size') * 13.1})
---
mandatory: True
question: |
We will ship that right away.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
metadata:
title: Under text
documentation: "https://docassemble.org/docs/fields.html#under text"
---
question: |
What are your favorite things to eat?
subquestion: |
Please be specific.
fields:
- Vegetable: target_variable
under text: E.g., eggplant, turnips
- Fruit: other_target_variable
under text: E.g., apples, oranges
---
question: Result of question
subquestion: |
target_variable is: "${ target_variable }"
mandatory: True

2 changes: 2 additions & 0 deletions docassemble_base/docassemble/base/data/sources/base-words.yml
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@
"Register with Google": Null
"Register with Twitter": Null
"Register with your mobile phone": Null
"Register with Zitadel": Null
"Registration attempt": Null
"Registration is invite only": Null
"remaining on disk": Null
Expand Down Expand Up @@ -910,6 +911,7 @@
"Sign in with Keycloak": Null
"Sign in with Twitter": Null
"Sign in with your mobile phone": Null
"Sign in with Zitadel": Null
"Sign Out": Null
"Sign up": Null
"Sign Your Name": Null
Expand Down
6 changes: 5 additions & 1 deletion docassemble_base/docassemble/base/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ def user_info():
user.current_filename = this_thread.current_question.from_source.path
except:
user.current_filename = None
try:
user.current_section = this_thread.current_section or get_user_dict()['nav'].current
except:
user.current_section = None
return user


Expand Down Expand Up @@ -3593,7 +3597,7 @@ def response(*pargs, **kwargs):

def json_response(data, response_code=None):
"""Sends data in JSON format as an HTTP response."""
raise ResponseError(json.dumps(data, sort_keys=True, indent=2) + "\n", content_type="application/json", response_code=response_code)
raise ResponseError(binaryresponse=(json.dumps(data, sort_keys=True, indent=2) + "\n").encode('utf-8'), content_type="application/json", response_code=response_code)


def variables_as_json(include_internal=False):
Expand Down
Loading

0 comments on commit 6347fa5

Please sign in to comment.