def post(self, request, project_uuid): """ View for email notifications regarding projects """ post_data = json.loads(request.body) username = post_data.get('username') ag = get_service_account_client() project = BaseProject.manager().get(ag, uuid=project_uuid) tasks.email_project_admins.apply_async(args=[ project.project_id, project_uuid, project.title, request.build_absolute_uri('{}/projects/{}/'.format( reverse('designsafe_data:data_depot'), project_uuid)), username ]) return JsonResponse({'status': 'ok'})
def project_by_uuid(uuid, prj_type): """Retrieves a project.""" agv = service_account() if prj_type == 'experimental': project = ExperimentalProject.manager().get(agv, uuid=uuid) elif prj_type == 'simulation': project = SimulationProject.manager().get(agv, uuid=uuid) elif prj_type == 'simulation': project = HybridSimulationProject.manager().get(agv, uuid=uuid) else: project = BaseProject.manager().get(agv, uuid=uuid) return project
def delete(self, request, project_id): if request.is_ajax(): post_data = json.loads(request.body) else: post_data = request.POST.copy() ag = get_service_account_client() project = BaseProject.manager().get(ag, uuid=project_id) project.manager().set_client(ag) team_members_to_rm = [user['username'] for user in post_data['users'] \ if user['memberType'] == 'teamMember'] co_pis_to_rm = [user['username'] for user in post_data['users'] \ if user['memberType'] == 'coPi'] project.remove_team_members(team_members_to_rm) project.remove_co_pis(co_pis_to_rm) tasks.check_project_files_meta_pems.apply_async(args=[project.uuid], queue='api') return JsonResponse({'status': 'ok'})
def post(self, request, project_id): if request.is_ajax(): post_data = json.loads(request.body) else: post_data = request.POST.copy() team_members_to_add = [user['username'] for user in post_data.get('users') \ if user['memberType'] == 'teamMember'] co_pis_to_add = [user['username'] for user in post_data.get('users') \ if user['memberType'] == 'coPi'] ag = get_service_account_client() project = BaseProject.manager().get(ag, uuid=project_id) project.manager().set_client(ag) #TODO: This should run on a task project.add_team_members(team_members_to_add) project.add_co_pis(co_pis_to_add) tasks.check_project_files_meta_pems.apply_async(args=[project.uuid ], queue='api') #TODO: This should also run on a task for username in team_members_to_add+co_pis_to_add: collab_users = get_user_model().objects.filter(username=username) collab_users = [] if collab_users: collab_user = collab_users[0] try: collab_user.profile.send_mail( "[Designsafe-CI] You have been added to a project!", "<p>You have been added to the project <em> {title} </em> as PI</p><p>You can visit the project using this url <a href=\"{url}\">{url}</a>".format(title=project.title, url=request.build_absolute_uri(reverse('designsafe_data:data_depot') + '/projects/%s/' % (project.uuid,)))) except DesignSafeProfile.DoesNotExist as err: logger.info("Could not send email to user %s", collab_user) body = "<p>You have been added to the project <em> {title} </em> as PI</p><p>You can visit the project using this url <a href=\"{url}\">{url}</a>".format(title=project.title, url=request.build_absolute_uri(reverse('designsafe_data:data_depot') + '/projects/%s/' % (project.uuid,))) send_mail( "[Designsafe-CI] You have been added to a project!", body, settings.DEFAULT_FROM_EMAIL, [collab_user.email], html_message=body) #logger.exception(err) return JsonResponse(project.collaborators)
def get(self, request, project_id): ag = request.user.agave_oauth.client project = BaseProject.manager().get(ag, uuid=project_id) return JsonResponse(project.collaborators)
def post(self, request): """ Create a new Project. Projects and the root File directory for a Project should be owned by the portal, with roles/permissions granted to the creating user. 1. Create the metadata record for the project 2. Create a directory on the projects storage system named after the metadata uuid 3. Associate the metadata uuid and file uuid :param request: :return: The newly created project :rtype: JsonResponse """ # portal service account needs to create the objects on behalf of the user ag = get_service_account_client() if request.is_ajax(): post_data = json.loads(request.body) else: post_data = request.POST.copy() # create Project (metadata) metrics.info('projects', extra={ 'user': request.user.username, 'sessionId': getattr(request.session, 'session_key', ''), 'operation': 'project_create', 'info': { 'postData': post_data } }) prj = BaseProject() prj.manager().set_client(ag) prj.save(ag) project_uuid = prj.uuid prj.title = post_data.get('title') prj.award_number = post_data.get('awardNumber', '') prj.project_type = post_data.get('projectType', 'other') prj.associated_projects = post_data.get('associatedProjects', {}) prj.description = post_data.get('description', '') prj.pi = post_data.get('pi') prj.keywords = post_data.get('keywords', '') prj.project_id = post_data.get('projectId', '') prj.save(ag) # create Project Directory on Managed system metrics.info('projects', extra={ 'user': request.user.username, 'sessionId': getattr(request.session, 'session_key', ''), 'operation': 'base_directory_create', 'info': { 'systemId': Project.STORAGE_SYSTEM_ID, 'uuid': prj.uuid } }) project_storage_root = BaseFileResource(ag, Project.STORAGE_SYSTEM_ID, '/') project_storage_root.mkdir(prj.uuid) # Wrap Project Directory as private system for project project_system_tmpl = template_project_storage_system(prj) project_system_tmpl['storage']['rootDir'] = \ project_system_tmpl['storage']['rootDir'].format(project_uuid) metrics.info('projects', extra={ 'user': request.user.username, 'sessionId': getattr(request.session, 'session_key', ''), 'operation': 'private_system_create', 'info': { 'id': project_system_tmpl.get('id'), 'site': project_system_tmpl.get('site'), 'default': project_system_tmpl.get('default'), 'status': project_system_tmpl.get('status'), 'description': project_system_tmpl.get('description'), 'name': project_system_tmpl.get('name'), 'globalDefault': project_system_tmpl.get('globalDefault'), 'available': project_system_tmpl.get('available'), 'public': project_system_tmpl.get('public'), 'type': project_system_tmpl.get('type'), 'storage': { 'homeDir': project_system_tmpl.get('storage', {}).get('homeDir'), 'rootDir': project_system_tmpl.get('storage', {}).get('rootDir') } } }) ag.systems.add(body=project_system_tmpl) # grant initial permissions for creating user and PI, if exists metrics.info('projects', extra={ 'user': request.user.username, 'sessionId': getattr(request.session, 'session_key', ''), 'operation': 'initial_pems_create', 'info': { 'collab': request.user.username, 'pi': prj.pi } }) prj.add_team_members([request.user.username]) tasks.set_facl_project.apply_async( args=[prj.uuid, [request.user.username]], queue='api') if prj.pi and prj.pi != request.user.username: prj.add_team_members([prj.pi]) tasks.set_facl_project.apply_async(args=[prj.uuid, [prj.pi]], queue='api') collab_users = get_user_model().objects.filter(username=prj.pi) if collab_users: collab_user = collab_users[0] try: collab_user.profile.send_mail( "[Designsafe-CI] You have been added to a project!", "<p>You have been added to the project <em> {title} </em> as PI</p><p>You can visit the project using this url <a href=\"{url}\">{url}</a>" .format(title=prj.title, url=request.build_absolute_uri( reverse('designsafe_data:data_depot') + '/projects/%s/' % (prj.uuid, )))) except DesignSafeProfile.DoesNotExist as err: logger.info("Could not send email to user %s", collab_user) body = "<p>You have been added to the project <em> {title} </em> as PI</p><p>You can visit the project using this url <a href=\"{url}\">{url}</a>".format( title=prj.title, url=request.build_absolute_uri( reverse('designsafe_data:data_depot') + '/projects/%s/' % (prj.uuid, ))) send_mail( "[Designsafe-CI] You have been added to a project!", body, settings.DEFAULT_FROM_EMAIL, [collab_user.email], html_message=body) prj.add_admin('prjadmin') tasks.set_project_id.apply_async(args=[prj.uuid], queue="api") return JsonResponse(prj.to_body_dict(), safe=False)