Skip to content

Commit

Permalink
sessions are unique changed to be more like require login in its effe…
Browse files Browse the repository at this point in the history
…ct on functions; fixed issue with email
  • Loading branch information
jhpyle committed Aug 15, 2024
1 parent 54cb4f2 commit 6fa92e3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [1.5.1] - 2024-08-15

### Fixed
- Problem with sending email due to change in Flask-Mail.
- The effect of `sessions are unique` was changed to be more like
the effect of `require login`.

## [1.5.0] - 2024-08-14

### Added
Expand Down
1 change: 1 addition & 0 deletions docassemble_base/docassemble/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def load(**kwargs):
else:
new_item['roles'] = None
new_item['require_login'] = bool(item.get('require login', False))
new_item['unique_sessions'] = bool(item.get('sessions are unique', False))
new_admin_interviews.append(new_item)
else:
config_error("Unrecognized item in administrative interviews.")
Expand Down
10 changes: 8 additions & 2 deletions docassemble_base/docassemble/base/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8353,11 +8353,14 @@ def allowed_to_access(self, is_anonymous=False, has_roles=None):
if has_roles is not None:
return len(set(roles).intersection(set(has_roles))) > 0
if is_anonymous:
unique_sessions = False
require_login = False
for metadata in self.metadata:
if 'require login' in metadata:
require_login = bool(metadata['require login'])
if require_login:
if 'sessions are unique' in metadata:
unique_sessions = bool(metadata['sessions are unique'])
if require_login or unique_sessions:
return False
return True

Expand Down Expand Up @@ -8419,11 +8422,14 @@ def allowed_to_see_listed(self, is_anonymous=False, has_roles=None):
if has_roles is not None:
return len(set(roles).intersection(set(has_roles))) > 0
if is_anonymous:
unique_sessions = False
require_login = False
for metadata in self.metadata:
if 'require login' in metadata:
require_login = bool(metadata['require login'])
if require_login:
if 'sessions are unique' in metadata:
unique_sessions = bool(metadata['sessions are unique'])
if require_login or unique_sessions:
return False
return True

Expand Down
3 changes: 2 additions & 1 deletion docassemble_webapp/docassemble/webapp/da_flask_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, subject='',
recipients=None,
body=None,
html=None,
alts={},
sender=None,
cc=None,
bcc=None,
Expand All @@ -52,6 +53,6 @@ def __init__(self, subject='',
mail_options=None,
rcpt_options=None):
null_sender = sender is None
super().__init__(subject, recipients, body, html, sender, cc, bcc, attachments, reply_to, date, charset, extra_headers, mail_options, rcpt_options)
super().__init__(subject, recipients, body, html, alts, sender, cc, bcc, attachments, reply_to, date, charset, extra_headers, mail_options, rcpt_options)
if null_sender:
self.sender = None
12 changes: 10 additions & 2 deletions docassemble_webapp/docassemble/webapp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6863,7 +6863,7 @@ def index(action_argument=None, refer=None):
session_id = None
if reset_interview == 2:
delete_session_sessions()
if (not reset_interview) and (unique_sessions is True or (isinstance(unique_sessions, list) and len(unique_sessions) and current_user.has_role(*unique_sessions))):
if (not reset_interview) and (unique_sessions is True or (isinstance(unique_sessions, list) and len(unique_sessions) > 0 and current_user.has_role(*unique_sessions))):
session_id, encrypted = get_existing_session(yaml_filename, secret)
if session_id is None:
user_code, user_dict = reset_session(yaml_filename, secret)
Expand Down Expand Up @@ -31797,7 +31797,7 @@ def is_not(self, interview):
return self.interview != interview

def can_use(self):
if self.require_login and current_user.is_anonymous:
if (self.require_login or self.unique_sessions) and current_user.is_anonymous:
return False
if self.roles is None:
return True
Expand Down Expand Up @@ -31869,6 +31869,7 @@ def set_admin_interviews():
menu_item.label = item['label']
menu_item.roles = item['roles']
menu_item.require_login = item['require_login']
menu_item.unique_sessions = item['unique_sessions']
admin_interviews.append(menu_item)
elif 'interview' in item and isinstance(item['interview'], str):
try:
Expand Down Expand Up @@ -31945,6 +31946,13 @@ def set_admin_interviews():
for metadata in interview.metadata:
if 'require login' in metadata:
admin_interview.require_login = bool(metadata['require login'])
admin_interview.unique_sessions = False
if 'sessions are unique' in item and item['sessions are unique'] is not None:
admin_interview.unique_sessions = bool(item['sessions are unique'])
else:
for metadata in interview.metadata:
if 'sessions are unique' in metadata:
admin_interview.unique_sessions = bool(metadata['sessions are unique'])
admin_interviews.append(admin_interview)
else:
logmessage("item in administrative interviews must contain a valid interview name")
Expand Down

0 comments on commit 6fa92e3

Please sign in to comment.