Skip to content

Commit

Permalink
Py3 fix for Project Task Comments
Browse files Browse the repository at this point in the history
CCC: Message Donors re: Items; Withdraw Action Button in the participant
list view should only be seen for Applies not Invites
  • Loading branch information
flavour committed Jan 6, 2020
1 parent 824c784 commit a85846b
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 104 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-dev-3416-ga45199d (2020-01-03 14:56:31)
b'824c7843d' (2020-01-06 17:09:05)
2 changes: 1 addition & 1 deletion controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ def comment_parse(comment, comments, task_id=None):
person = row.pr_person
user = row[utable._tablename]
username = s3_fullname(person)
email = user.email.strip().lower()
email = user.email.strip().lower().encode("utf-8")
import hashlib
hash = hashlib.md5(email).hexdigest()
url = "http://www.gravatar.com/%s" % hash
Expand Down
94 changes: 74 additions & 20 deletions modules/s3/s3aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,10 +1977,11 @@ def s3_import_prep(self, data):
TRANSLATE = current.deployment_settings.get_L10n_translate_org_organisation()
if TRANSLATE:
ltable = s3db.org_organisation_name

def add_org(name, parent=None):
""" Helper to add a New Organisation """
organisation_id = otable.insert(name=name)
record = Storage(id=organisation_id)
organisation_id = otable.insert(name = name)
record = Storage(id = organisation_id)
update_super(otable, record)
set_record_owner(otable, organisation_id)
# @ToDo: Call onaccept?
Expand All @@ -1991,21 +1992,21 @@ def add_org(name, parent=None):
link_id = btable.insert(organisation_id = records.first().id,
branch_id = organisation_id)
onaccept = s3db.get_config("org_organisation_branch", "onaccept")
callback(onaccept, Storage(vars=Storage(id=link_id)))
callback(onaccept, Storage(vars = Storage(id = link_id)))
elif len(records) > 1:
# Ambiguous
current.log.debug("Cannot set branch link for new Organisation %s as there are multiple matches for parent %s" % (name, parent))
else:
# Create Parent
parent_id = otable.insert(name=parent)
update_super(otable, Storage(id=parent_id))
parent_id = otable.insert(name = parent)
update_super(otable, Storage(id = parent_id))
set_record_owner(otable, parent_id)
# @ToDo: Call onaccept?
# Create link
link_id = btable.insert(organisation_id = parent_id,
branch_id = organisation_id)
onaccept = s3db.get_config("org_organisation_branch", "onaccept")
callback(onaccept, Storage(vars=Storage(id=link_id)))
callback(onaccept, Storage(vars = Storage(id = link_id)))
return (organisation_id, record.pe_id)

def org_lookup(org_full):
Expand Down Expand Up @@ -2074,9 +2075,51 @@ def org_lookup(org_full):

return (organisation_id, pe_id)

def person_lookup(details):
""" Helper to lookup a Person """
first_name, last_name, email = details.split("+")

# Rare edge case to set realm as individuals so not defining in top-scope
ctable = s3db.pr_contact
ptable = s3db.pr_person
query = (ptable.first_name.lower() == first_name.lower()) & \
(ptable.last_name.lower() == last_name.lower()) & \
(ptable.deleted != True) & \
(ctable.pe_id == ptable.pe_id) & \
(ctable.contact_method == "EMAIL") & \
(ctable.value == email)

records = db(query).select(ptable.id,
ptable.pe_id,
limitby = (0, 2))
if len(records) == 1:
record = records.first()
person_id = record.id
pe_id = record.pe_id
elif len(records) > 1:
# Ambiguous
current.log.debug("Cannot set Person %s for user as there are multiple matches" % details)
person_id = ""
pe_id = ""
else:
# Add a new Person
person_id = ptable.insert(first_name = first_name,
last_name = last_name,
)
record = Storage(id = person_id)
update_super(ptable, record)
pe_id = record.pe_id
# Persons need Email defining otherwise they won't match in s3_link_to_person
ctable.insert(pe_id = pe_id,
contact_method = "EMAIL",
value = email,
)

return (person_id, pe_id)

# Memberships
elements = tree.getroot().xpath("/s3xml//resource[@name='auth_membership']/data[@field='pe_id']")
looked_up = dict(org_organisation = {})
looked_up = {"org_organisation": {}} # Most common, so added outside loop
for element in elements:
pe_string = element.text

Expand All @@ -2093,20 +2136,26 @@ def org_lookup(org_full):
if pe_tablename == "org_organisation" and pe_field == "name":
# This is a non-integer, so must be 1st or only phase
(record_id, pe_id) = org_lookup(pe_value)
elif pe_tablename == "pr_person" and pe_field == "details":
# This is a non-integer, so must be 1st or only phase
if pe_tablename not in looked_up:
looked_up[pe_tablename] = {}
# Persons need Email defining otherwise they won't match in s3_link_to_person
(record_id, pe_id) = person_lookup(pe_value)
else:
table = s3db[pe_tablename]
if pe_tablename not in looked_up:
looked_up[pe_tablename] = {}
record = db(table[pe_field] == pe_value).select(table.id, # Stored for Org/Groups later
table.pe_id,
limitby=(0, 1)
limitby = (0, 1)
).first()
if record:
record_id = record.id
else:
# Add a new record
record_id = table.insert(**{pe_field: pe_value})
record = Storage(id=record_id)
record = Storage(id = record_id)
update_super(table, record)
set_record_owner(table, record_id)
pe_id = record.pe_id
Expand Down Expand Up @@ -2142,10 +2191,10 @@ def org_lookup(org_full):
# organisation_id = str(organisation_id)
# element.text = organisation_id
# # Store in case we get called again with same value
# orgs[org_full] = dict(id=organisation_id)
# orgs[org_full] = {"id": organisation_id}
# else:
# # Store in case we get called again with same value
# orgs[org_full] = dict(id=org_full)
# orgs[org_full] = {"id": org_full}

# Organisation Groups
#elements = tree.getroot().xpath("/s3xml//resource[@name='auth_user']/data[@field='org_group_id']")
Expand All @@ -2166,22 +2215,22 @@ def org_lookup(org_full):
# except ValueError:
# # This is a non-integer, so must be 1st or only phase
# record = db(gtable.name == name).select(gtable.id,
# limitby=(0, 1)
# limitby = (0, 1)
# ).first()
# if record:
# org_group_id = record.id
# else:
# # Add a new record
# org_group_id = gtable.insert(name=name)
# update_super(gtable, Storage(id=org_group_id))
# org_group_id = gtable.insert(name = name)
# update_super(gtable, Storage(id = org_group_id))
# # Replace string with id
# org_group_id = str(org_group_id)
# element.text = org_group_id
# # Store in case we get called again with same value
# org_groups[name] = dict(id=org_group_id)
# org_groups[name] = {"id": org_group_id}
# else:
# # Store in case we get called again with same value
# org_groups[name] = dict(id=name)
# org_groups[name] = {"id": name}

# -------------------------------------------------------------------------
@staticmethod
Expand Down Expand Up @@ -2691,8 +2740,9 @@ def s3_user_profile_onaccept(form):

# -------------------------------------------------------------------------
def s3_link_to_person(self,
user=None,
organisation_id=None):
user = None,
organisation_id = None
):
"""
Links user accounts to person registry entries
Expand Down Expand Up @@ -2858,7 +2908,8 @@ def s3_link_to_person(self,
(ctable.value.lower() == email)
person = db(query).select(ptable.id,
ptable.pe_id,
limitby=(0, 1)).first()
limitby = (0, 1)
).first()
else:
# Can't find a match without an email address
person = None
Expand All @@ -2870,6 +2921,7 @@ def s3_link_to_person(self,
other = db(ltable.pe_id == person.pe_id).select(ltable.id,
limitby=(0, 1),
).first()

if person and not other:
# Match found, and it isn't linked to another user account
# => link to this person record (+update it)
Expand All @@ -2884,7 +2936,9 @@ def s3_link_to_person(self,
owner.realm_entity = realm_entity

# Insert a link
ltable.insert(user_id=user.id, pe_id=pe_id)
ltable.insert(user_id = user.id,
pe_id = pe_id,
)

# Assign ownership of the Person record
person.update_record(**owner)
Expand Down
8 changes: 4 additions & 4 deletions modules/s3/s3import.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ def generate_job(self, r, **attr):
output = None
if self.ajax:
sfilename = ofilename = r.post_vars["file"].filename
upload_id = table.insert(controller=self.controller,
function=self.function,
filename=ofilename,
upload_id = table.insert(controller = self.controller,
function = self.function,
filename = ofilename,
file = sfilename,
user_id=current.session.auth.user.id
user_id = current.session.auth.user.id
)
else:
title = self.uploadTitle
Expand Down
5 changes: 3 additions & 2 deletions modules/s3db/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,9 @@ def lookup_rows(self, key, values, fields=None):
if show_name or show_phone:
ptable = s3db.pr_person
ltable = s3db.pr_person_user
left = ptable.on((table.id == ltable.user_id) & \
(ltable.pe_id == ptable.pe_id))
left = [ltable.on(table.id == ltable.user_id),
ptable.on(ltable.pe_id == ptable.pe_id),
]
else:
left = None

Expand Down
4 changes: 3 additions & 1 deletion modules/s3db/hrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,8 @@ def hrm_human_resource_onaccept(form):
def hrm_compose():
"""
Send message to people/teams/participants
@ToDo: Better rewritten as an S3Method
"""

s3db = current.s3db
Expand Down Expand Up @@ -7785,7 +7787,7 @@ def postp(r, output):
"url": URL(f="compose",
vars = {"group_id": "[id]"}),
"_class": "action-btn send",
"label": str(T("Send Message"))})
"label": s3_str(T("Send Message"))})

return output
s3.postp = postp
Expand Down
21 changes: 17 additions & 4 deletions modules/s3db/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7962,13 +7962,26 @@ def apply_method(self, r, **attr):
def pr_compose():
"""
Send message to people/teams/forums
@ToDo: Better rewritten as an S3Method
"""

#s3db = current.s3db
get_vars = current.request.get_vars
#pe_id = None

#if "person.id" in get_vars:
# # CCC uses a custom version for messaging Donors re: Donations
# fieldname = "person.id"
# record_id = get_vars.get(fieldname)
# table = current.s3db.pr_person
# title = current.T("Message Person")
# query = (table.id == record_id)
# # URL to redirect to after message sent
# url = URL(f="person", args=record_id)

#elif "forum.id" in get_vars:
if "forum.id" in get_vars:
# Used by? WACOP?
fieldname = "forum.id"
record_id = get_vars.get(fieldname)
pe_id = get_vars.pe_id
Expand All @@ -7992,12 +8005,12 @@ def pr_compose():
# db = current.db
# pe = db(query).select(table.pe_id,
# limitby=(0, 1)).first()
# if not pe:
# try:
# pe_id = pe.pe_id
# except:
# current.session.error = current.T("Record not found")
# redirect(URL(f="index"))

# pe_id = pe.pe_id

# Create the form
output = current.msg.compose(recipient = pe_id,
url = url)
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/CCC/Demo/users.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Allerdale,OrgAdmin,[email protected],eden,ORG_ADMIN,Allerdale Communit
Eden,Volunteer,[email protected],eden,VOLUNTEER,Eden Community Organisation,staff
Eden,OrgAdmin,[email protected],eden,ORG_ADMIN,Eden Community Organisation,staff
Reserve,Volunteer,[email protected],eden,"RESERVE/pr_forum.name=Reserves",,
Corporate,Donor,[email protected],eden,"DONOR/pr_forum.name=Donors",,
Corporate,Donor,[email protected],eden,"DONOR/[email protected]",,
Group,Leader,[email protected],eden,"GROUP_ADMIN/pr_group.name=Helpers",,
Police,Liaison,[email protected],eden,AGENCY,Agency Group,staff
5 changes: 3 additions & 2 deletions modules/templates/CCC/auth_roles.csv
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ AGENCY,Agency Staff,,req,need,,CREATE|READ|UPDATE|DELETE,,,
AGENCY,Agency Staff,,,,req_need,READ,,any,
AGENCY,Agency Staff,,,,req_need,CREATE|READ|UPDATE|DELETE,,,
AGENCY,Agency Staff,,,,req_need_person,CREATE|READ|UPDATE|DELETE,,,
AGENCY,Agency Staff,,supply,person_item,,READ,,,
DONOR,Donor,,dummy,dummy,,READ,,,
AGENCY,Agency Staff,,supply,person_item,,READ|UPDATE,,,
DONOR,Donor,,project,task,,READ,,,
DONOR,Donor,,project,comments,,CREATE|READ|UPDATE,,,
GROUP_ADMIN,Volunteer Group Leader,,cms,post,,READ,,,
GROUP_ADMIN,Volunteer Group Leader,,pr,group,,CREATE|READ|UPDATE,,,
GROUP_ADMIN,Volunteer Group Leader,,,,pr_group,CREATE|READ|UPDATE,,,
Expand Down
Loading

0 comments on commit a85846b

Please sign in to comment.