73 Args: |
73 Args: |
74 entity : A request containing the information needed to create the message |
74 entity : A request containing the information needed to create the message |
75 """ |
75 """ |
76 |
76 |
77 from soc.logic.models.user import logic as user_logic |
77 from soc.logic.models.user import logic as user_logic |
78 |
78 from soc.views.models.role import ROLE_VIEWS |
79 # get the user the request is for |
|
80 properties = {'link_id': entity.link_id } |
|
81 to_user = user_logic.getForFields(properties, unique=True) |
|
82 |
79 |
83 invitation_url = "http://%(host)s%(index)s" % { |
80 invitation_url = "http://%(host)s%(index)s" % { |
84 'host' : system.getHostname(), |
81 'host' : system.getHostname(), |
85 'index': redirects.getInviteProcessRedirect(entity, None), |
82 'index': redirects.getInviteProcessRedirect(entity, None), |
86 } |
83 } |
87 |
84 |
|
85 role_params = ROLE_VIEWS[entity.role].getParams() |
|
86 |
88 message_properties = { |
87 message_properties = { |
89 'role_verbose' : entity.role_verbose, |
88 'role_verbose' : role_params['name'], |
90 'group': entity.scope.name, |
89 'group': entity.group.name, |
91 'invitation_url': invitation_url, |
90 'invitation_url': invitation_url, |
92 } |
91 } |
93 |
92 |
94 subject = DEF_INVITATION_MSG_FMT % { |
93 subject = DEF_INVITATION_MSG_FMT % { |
95 'role_verbose' : entity.role_verbose, |
94 'role_verbose' : role_params['name'], |
96 'group' : entity.scope.name |
95 'group' : entity.group.name |
97 } |
96 } |
98 |
97 |
99 template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE |
98 template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE |
100 |
99 |
101 from_user = user_logic.getForCurrentAccount() |
100 from_user = user_logic.getForCurrentAccount() |
102 |
101 |
103 sendNotification(to_user, from_user, message_properties, subject, template) |
102 sendNotification(entity.user, from_user, message_properties, subject, template) |
104 |
103 |
105 |
104 |
106 def sendNewRequestNotification(request_entity): |
105 def sendNewRequestNotification(request_entity): |
107 """Sends out a notification to the persons who can process this Request. |
106 """Sends out a notification to the persons who can process this Request. |
108 |
107 |
120 # retrieve the Role Logics which we should query on |
119 # retrieve the Role Logics which we should query on |
121 role_logic = ROLE_LOGICS[request_entity.role] |
120 role_logic = ROLE_LOGICS[request_entity.role] |
122 role_logics_to_notify = role_logic.getRoleLogicsToNotifyUponNewRequest() |
121 role_logics_to_notify = role_logic.getRoleLogicsToNotifyUponNewRequest() |
123 |
122 |
124 # the scope of the roles is the same as the scope of the Request entity |
123 # the scope of the roles is the same as the scope of the Request entity |
125 fields = {'scope': request_entity.scope, |
124 fields = {'scope': request_entity.group, |
126 'status': 'active'} |
125 'status': 'active'} |
127 |
126 |
128 for role_logic in role_logics_to_notify: |
127 for role_logic in role_logics_to_notify: |
129 roles = role_logic.getForFields(fields) |
128 roles = role_logic.getForFields(fields) |
130 |
129 |
131 for role_entity in roles: |
130 for role_entity in roles: |
132 # TODO: this might lead to double notifications |
131 # TODO: this might lead to double notifications |
133 to_users.append(role_entity.user) |
132 to_users.append(role_entity.user) |
134 |
133 |
135 # get the user the request is from |
134 # get the user the request is from |
136 properties = {'link_id': request_entity.link_id } |
135 user_entity = request_entity.user |
137 user_entity = user_logic.getForFields(properties, unique=True) |
|
138 |
136 |
139 message_properties = { |
137 message_properties = { |
140 'requester_name': user_entity.name, |
138 'requester_name': user_entity.name, |
141 'entity': request_entity, |
139 'entity': request_entity, |
142 'request_url': redirects.getProcessRequestRedirect(request_entity, None)} |
140 'request_url': redirects.getProcessRequestRedirect(request_entity, None)} |
143 |
141 |
144 subject = DEF_NEW_REQUEST_MSG_FMT % { |
142 subject = DEF_NEW_REQUEST_MSG_FMT % { |
145 'requester': user_entity.name, |
143 'requester': user_entity.name, |
146 'role_verbose' : request_entity.role_verbose, |
144 'role_verbose' : request_entity.role, |
147 'group' : request_entity.scope.name |
145 'group' : request_entity.group.name |
148 } |
146 } |
149 |
147 |
150 template = DEF_NEW_REQUEST_NOTIFICATION_TEMPLATE |
148 template = DEF_NEW_REQUEST_NOTIFICATION_TEMPLATE |
151 |
149 |
152 for to_user in to_users: |
150 for to_user in to_users: |