Skip to content

Commit

Permalink
Link person record to org_group after registration/approval, fix org_…
Browse files Browse the repository at this point in the history
…group_id.represent
  • Loading branch information
nursix committed Dec 9, 2014
1 parent b0ea9ac commit 1203ab0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-1.1.0-devel-1647-g3be3a5c (2014-12-09 14:12:51)
nursix-1.1.0-devel-1652-gb0ea9ac (2014-12-09 14:12:10)
46 changes: 46 additions & 0 deletions modules/s3/s3aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,9 @@ def s3_link_user(self, user):
# Add to user Person Registry and Email/Mobile to pr_contact
person_id = self.s3_link_to_person(user, organisation_id)

if user.org_group_id:
self.s3_link_to_org_group(user, person_id)

utable = self.settings.table_user

link_user_to = user.link_user_to or utable.link_user_to.default
Expand Down Expand Up @@ -2716,6 +2719,49 @@ def s3_link_to_organisation(self, user):

return organisation_id

# -------------------------------------------------------------------------
def s3_link_to_org_group(self, user, person_id):
"""
Link a user account to an organisation group
@param user: the user account record
@param person_id: the person record ID associated with this user
"""

db = current.db
s3db = current.s3db

org_group_id = user.get("org_group_id")
if not org_group_id or not person_id:
return None

# Default status to "Member"
stable = s3db.org_group_person_status
query = (stable.name.lower() == "member") & \
(stable.deleted != True)
row = db(query).select(stable.id, limitby=(0, 1)).first()
if row:
status_id = row.id
else:
status_id = None

# Check if link exists
ltable = s3db.org_group_person
query = (ltable.person_id == person_id) & \
(ltable.org_group_id == org_group_id) & \
(ltable.deleted != True)
row = db(query).select(ltable.id, limitby=(0, 1)).first()
if not row:
# Make sure person record and org_group record exist
ptable = s3db.pr_person
gtable = s3db.org_group
if ptable[person_id] and gtable[org_group_id]:
ltable.insert(person_id=person_id,
org_group_id=org_group_id,
status_id=status_id,
)
return org_group_id

# -------------------------------------------------------------------------
def s3_link_to_human_resource(self,
user,
Expand Down
11 changes: 6 additions & 5 deletions modules/s3db/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,15 +1304,15 @@ def model(self):
super_entity = ("doc_entity", "pr_pentity"),
)

represent = S3Represent(lookup=tablename)
group_represent = S3Represent(lookup=tablename)
group_id = S3ReusableField("group_id", "reference %s" % tablename,
label = T(label),
# Always links via Link Tables
ondelete = "CASCADE",
represent = represent,
represent = group_represent,
requires = IS_EMPTY_OR(
IS_ONE_OF(db, "org_group.id",
represent,
group_represent,
sort=True,
)),
sortby = "name",
Expand Down Expand Up @@ -1400,7 +1400,7 @@ def model(self):

# Pass names back to global scope (s3.*)
return dict(org_group_id = group_id,
org_group_represent = represent,
org_group_represent = group_represent,
)

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -1500,7 +1500,8 @@ def model(self):
#
tablename = "org_group_person"
define_table(tablename,
self.org_group_id(empty = False,
self.org_group_id("org_group_id",
empty = False,
ondelete = "CASCADE",
),
self.pr_person_id(empty = False,
Expand Down

0 comments on commit 1203ab0

Please sign in to comment.