def get(self, workspace_id, email_id): # Return a rendered template #return render('/credentials_file.mako') # or, return a response response.content_type = "application/wsl" filename = "kwmo_creds.wsl" # Temporarily disabled - need to be debugged. if request.params.has_key('interactive') and str(request.params.get('interactive')) == "1": filename = c.workspace.name + ".wsl" response.headers['Content-disposition'] = 'attachment; filename="%s"' % ( filename.encode('latin1') ) #fix for IE response.headers['Pragma'] = 'public' response.headers['Cache-Control'] = 'max-age-0' errorStr = None #ws = Workspace.get_by(id= workspace_id) ws = c.workspace invitation = Invitation.get_by(email_id = email_id) if (ws and invitation): user = User.get_by(id = invitation.user_id, workspace=ws) if(user and ws.id==invitation.kws_id): c.invitation = invitation c.user = user c.workspace = ws conf = get_cached_kcd_external_conf_object() c.kcd_host = conf.kcd_host c.kcd_port = conf.kcd_port if ('password' in request.params): c.password = request.params['password'] if ('user_id' in session): c.password = session['password'] else: errorStr = "User was not invited to this workspace" else: errorStr = "Invalid email_id or workspace_id" if errorStr: c.errorStr = errorStr return render('credentials_file/error.mako') else: return render('credentials_file/get.mako')
def _login(self, invitation, password= None): # Set info in session. session['mode'] = MODE_WS session['email_id'] = invitation.email_id session['user_id'] = invitation.user_id session['secure'] = c.workspace.secured # TODO account for password changes session['password'] = password c.perms.addRole('normal') user = User.get_by(workspace_id=invitation.kws_id, id=invitation.user_id) if user: session['user'] = user.to_dict() # Save session. session.save() # Do a last minute permissions check on KCD. self._check_perms() # Redirect to teambox url. redirect_to(url('teambox', workspace_id = session['workspace_id']))
def show(self, workspace_id, email_id): workspace_id = int(workspace_id) email_id = int(email_id) # Set logout url. c.logout_url = url('teambox_pubws_logout', workspace_id=workspace_id, email_id=email_id) # Check if the workspace is public. self._check_public(workspace_id) if 'email_id' in session and session['email_id'] != email_id: # User is logged but wants to access a different email. Reinit session. log.debug("Reinitializing session because user is using another email id: previous='%s', new='%s'." \ % ( str(session['email_id']), str(email_id) ) ) init_session(c.workspace, reinit=True) notif = request.GET.get('notif', 0) if notif: # This is the sender (user 1)... [re-]login automatically. log.debug( "User is accessing a public workspace using a notification link... automatically log user in." ) user = User.get_by(workspace_id=workspace_id, id=1) log.debug( "Reinitializing session because user is logging as user 1 (notif management)." ) init_session(c.workspace, reinit=True) self._login(user) c.notif_flag = True else: if 'user' in session and session['user'] and session['user'][ 'id'] == 1: # Sender is logged (as a sender) but he's using a regular skurl link: logout. log.debug( "Reinitializing session because user was logged as user 1 but is using a regular skurl link." ) init_session(c.workspace, reinit=True) if not c.perms.hasRole('skurl'): # Give skurl role, if not already done. c.perms.addRole('skurl') # Save session. session.save() if not 'email_id' in session: # Set email information in session. # Instantiate a Kcd client. kc = KcdClient(get_cached_kcd_external_conf_object()) # Check that email ID is valid. email_info = kc.pubws_get_email_info(workspace_id, email_id) if not email_info: log.debug("PubWS: invalild email ID: %i" % (email_id)) abort(404) # Get the email sender. sender_user = User.get_by(workspace_id=workspace_id, id=1) sender = kbase.PropStore() sender.name = sender_user.real_name sender.email = sender_user.email # Get the email recipients (list of PropStores, having name and email keys). raw_recipients = kc.pubws_get_eid_recipient_identities( workspace_id, email_id) # Strip sender email from recipients, if needed. recipients = [] for recipient in raw_recipients: if recipient.email != sender.email: recipients.append(recipient) # Merge sender and recipients. identities = [sender] + recipients # Set needed informations in session. session['email_id'] = email_id session['email_info'] = email_info.to_dict() session['identities'] = map(lambda x: x.to_dict(), identities) session.save() # Get informations that will be published in the template. c.dyn_version = 15 c.email_info = session['email_info'] c.json_email_info_str = simplejson.dumps(c.email_info) c.identities = session['identities'] c.json_identities_str = simplejson.dumps(c.identities) # Check if a chat request was accepted lately (delay is hardcoded in accepted_lately()). c.user_id = None if 'user_id' in session and session['user_id']: c.user_id = session['user_id'] if ChatRequest.accepted_lately(workspace_id, session['user_id']): # Deny chat requests and allow chat since a request was accepted lately. self._set_chat_requests_perms(False) self._set_chat_perms(True) else: # Allow chat requests and deny chat since no request was accepted lately. self._set_chat_requests_perms(True) self._set_chat_perms(False) # Allow workspace creation request. self._set_ws_creation_requests_perms(True) # Save session. session.save() c.base_url_paths = kurl.get_base_url_paths( 'teambox_updater', 'teambox_post_chat', 'teambox_download', 'teambox_upload', 'teambox_pubws_set_identity', 'teambox_pubws_chat_request', 'teambox_pubws_chat_request_result', 'teambox_pubws_kfsup_request', 'teambox_pubws_kfsdown_request', 'teambox_pubws_create_request') # Get first update directly. flags = (StateRequest.STATE_FORCE_SYNC | StateRequest.STATE_WANT_PERMS | StateRequest.STATE_WANT_MEMBERS | StateRequest.STATE_WANT_KFS | StateRequest.STATE_WANT_PUBWS_INFO) params = {} if 'user_id' in session and session['user_id']: flags |= StateRequest.STATE_WANT_CHAT params['chat_channel_id'] = session['user_id'] updater_state_dict = state_request_get(c, session, flags, params) c.updater_state_json = simplejson.dumps(updater_state_dict) return render('/teambox/pubwsshow.mako')
def pb_set_identity(self, workspace_id): import select from kcd_lib import WorkspaceInvitee workspace_id = int(workspace_id) # Get the workspace. if not c.workspace.public: log.warning("pb_set_identity: Workspace %i is not public." % (workspace_id)) abort(404) # Get POST parameters. identity_id = request.params['identity_id'] identity_id = int(identity_id) # Shortcuts identity = session['identities'][identity_id] log.debug("Recipient: %s" % (str(identity))) if identity_id == 0: # This is the sender (user 1). user = User.get_by(workspace_id=workspace_id, id=1) self._login(user) log.debug("Found matching user(0): '%s'." % (str(user))) return {'result': 'ok', 'user': session['user']} # This is a real recipient... try to get the user. user = User.get_by(workspace_id=workspace_id, email=identity['email']) if user: self._login(user) log.debug("Found matching user(1): '%s'." % (str(user))) return {'result': 'ok', 'user': session['user']} # Instantiate a Kcd client. kc = KcdClient(get_cached_kcd_external_conf_object()) # Invite user. invitee = WorkspaceInvitee(real_name=identity['name'], email_address=identity['email']) junk_url, invitees = kc.invite_users(workspace_id, "empty message", [invitee]) if invitees[0].error: log.debug("User could not be invited: '%s'." % (str(invitees[0].error))) raise Exception('Internal error.') # Get user. If not present, retry a few times, until new user is fetched by kwsfetcher or until timeout. wait_seconds = 0.5 timeout_seconds = 8 time_started = time.time() while 1: # Get user, if it exists (fetched by kwsfetcher). user = User.get_by(workspace_id=workspace_id, email=identity['email']) if user: self._login(user) log.debug("Found matching user (2): '%s'." % (str(user))) return {'result': 'ok', 'user': session['user']} # Check for timeout. if time.time() > time_started + timeout_seconds: break # Wait select.select([], [], [], wait_seconds) # Reached timeout. log.error( "Error: reached end of pb_set_identity(). KWSFetcher might be too loaded or down." ) raise Exception('Temporary server error: please try again later.')
def show(self, workspace_id, email_id): workspace_id = int(workspace_id) email_id = int(email_id) # Set logout url. c.logout_url = url('teambox_pubws_logout', workspace_id=workspace_id, email_id=email_id) # Check if the workspace is public. self._check_public(workspace_id) if 'email_id' in session and session['email_id'] != email_id: # User is logged but wants to access a different email. Reinit session. log.debug("Reinitializing session because user is using another email id: previous='%s', new='%s'." \ % ( str(session['email_id']), str(email_id) ) ) init_session(c.workspace, reinit=True) notif = request.GET.get('notif', 0) if notif: # This is the sender (user 1)... [re-]login automatically. log.debug("User is accessing a public workspace using a notification link... automatically log user in.") user = User.get_by(workspace_id=workspace_id, id=1) log.debug("Reinitializing session because user is logging as user 1 (notif management).") init_session(c.workspace, reinit=True) self._login(user) c.notif_flag = True else: if 'user' in session and session['user'] and session['user']['id'] == 1: # Sender is logged (as a sender) but he's using a regular skurl link: logout. log.debug("Reinitializing session because user was logged as user 1 but is using a regular skurl link.") init_session(c.workspace, reinit=True) if not c.perms.hasRole('skurl'): # Give skurl role, if not already done. c.perms.addRole('skurl') # Save session. session.save() if not 'email_id' in session: # Set email information in session. # Instantiate a Kcd client. kc = KcdClient(get_cached_kcd_external_conf_object()) # Check that email ID is valid. email_info = kc.pubws_get_email_info(workspace_id, email_id) if not email_info: log.debug("PubWS: invalild email ID: %i" % ( email_id ) ) abort(404) # Get the email sender. sender_user = User.get_by(workspace_id=workspace_id, id=1) sender = kbase.PropStore() sender.name = sender_user.real_name sender.email = sender_user.email # Get the email recipients (list of PropStores, having name and email keys). raw_recipients = kc.pubws_get_eid_recipient_identities(workspace_id, email_id) # Strip sender email from recipients, if needed. recipients = [] for recipient in raw_recipients: if recipient.email != sender.email: recipients.append(recipient) # Merge sender and recipients. identities = [sender] + recipients # Set needed informations in session. session['email_id'] = email_id session['email_info'] = email_info.to_dict() session['identities'] = map(lambda x: x.to_dict(), identities) session.save() # Get informations that will be published in the template. c.dyn_version = 15 c.email_info = session['email_info'] c.json_email_info_str = simplejson.dumps(c.email_info) c.identities = session['identities'] c.json_identities_str = simplejson.dumps(c.identities) # Check if a chat request was accepted lately (delay is hardcoded in accepted_lately()). c.user_id = None if 'user_id' in session and session['user_id']: c.user_id = session['user_id'] if ChatRequest.accepted_lately(workspace_id, session['user_id']): # Deny chat requests and allow chat since a request was accepted lately. self._set_chat_requests_perms(False) self._set_chat_perms(True) else: # Allow chat requests and deny chat since no request was accepted lately. self._set_chat_requests_perms(True) self._set_chat_perms(False) # Allow workspace creation request. self._set_ws_creation_requests_perms(True) # Save session. session.save() c.base_url_paths = kurl.get_base_url_paths( 'teambox_updater', 'teambox_post_chat', 'teambox_download', 'teambox_upload', 'teambox_pubws_set_identity', 'teambox_pubws_chat_request', 'teambox_pubws_chat_request_result', 'teambox_pubws_kfsup_request', 'teambox_pubws_kfsdown_request', 'teambox_pubws_create_request') # Get first update directly. flags = ( StateRequest.STATE_FORCE_SYNC | StateRequest.STATE_WANT_PERMS | StateRequest.STATE_WANT_MEMBERS | StateRequest.STATE_WANT_KFS | StateRequest.STATE_WANT_PUBWS_INFO ) params = { } if 'user_id' in session and session['user_id']: flags |= StateRequest.STATE_WANT_CHAT params['chat_channel_id'] = session['user_id'] updater_state_dict = state_request_get(c, session, flags, params) c.updater_state_json = simplejson.dumps(updater_state_dict) return render('/teambox/pubwsshow.mako')
def pb_set_identity(self, workspace_id): import select from kcd_lib import WorkspaceInvitee workspace_id = int(workspace_id) # Get the workspace. if not c.workspace.public: log.warning("pb_set_identity: Workspace %i is not public." % ( workspace_id ) ) abort(404) # Get POST parameters. identity_id = request.params['identity_id'] identity_id = int(identity_id) # Shortcuts identity = session['identities'][identity_id] log.debug("Recipient: %s" % ( str(identity) ) ) if identity_id == 0: # This is the sender (user 1). user = User.get_by(workspace_id=workspace_id, id=1) self._login(user) log.debug("Found matching user(0): '%s'." % ( str(user) ) ) return { 'result' : 'ok', 'user' : session['user'] } # This is a real recipient... try to get the user. user = User.get_by(workspace_id=workspace_id, email=identity['email']) if user: self._login(user) log.debug("Found matching user(1): '%s'." % ( str(user) ) ) return { 'result' : 'ok', 'user' : session['user'] } # Instantiate a Kcd client. kc = KcdClient(get_cached_kcd_external_conf_object()) # Invite user. invitee = WorkspaceInvitee(real_name=identity['name'], email_address=identity['email']) junk_url, invitees = kc.invite_users(workspace_id, "empty message", [invitee]) if invitees[0].error: log.debug("User could not be invited: '%s'." % ( str(invitees[0].error) ) ) raise Exception('Internal error.') # Get user. If not present, retry a few times, until new user is fetched by kwsfetcher or until timeout. wait_seconds = 0.5 timeout_seconds = 8 time_started = time.time() while 1: # Get user, if it exists (fetched by kwsfetcher). user = User.get_by(workspace_id=workspace_id, email=identity['email']) if user: self._login(user) log.debug("Found matching user (2): '%s'." % ( str(user) ) ) return { 'result' : 'ok', 'user' : session['user'] } # Check for timeout. if time.time() > time_started + timeout_seconds: break # Wait select.select([], [], [], wait_seconds) # Reached timeout. log.error("Error: reached end of pb_set_identity(). KWSFetcher might be too loaded or down."); raise Exception('Temporary server error: please try again later.');