Example #1
0
 def remove_project(user_id, project_id, email):
     query = f"""
             SELECT 
                 [creator]
             FROM
                 [prj].[project]
             WHERE
                 [ProjectId] = '{project_id}'
             """
     conn = Database.connect()
     cursor = conn.cursor()
     results = Database.execute_query(query, cursor)
     conn.close()
     if user_id == results[0][0]:
         remove_member = User.get_user_from_email(email)
         if remove_member is not None:
             query = """
                     [prj].[RemoveProject] @UserId = ?, @ProjectId = ?
                     """
             params = (user_id, project_id)
             conn = Database.connect()
             cursor = conn.cursor()
             results = Database.execute_sproc(query, params, cursor)
             if results['Status'] == 201:
                 cursor.commit()
             conn.close()
             return results
         else:
             return {'Status': 400, 'Message': 'There is no account associated with this email'}
     else:
         return {'Status': 400, 'Message':'This user is not the owner of the project'}
Example #2
0
 def create_institution(institution_model):
     query = f"""
             [usr].[CreateInstitution] @Name = ?, @Desc = ?, @Owner = ?
             """
     params = (institution_model.get_name(), institution_model.get_desc(), institution_model.get_owner())
     conn = Database.connect()
     cursor = conn.cursor()
     results = Database.execute_sproc(query, params, cursor)
     if results['Status'] == 201:
         cursor.commit()
     conn.close()
     return results
Example #3
0
 def leave_project(user_id, project_id):
     query = """
             [prj].[RemoveProject] @UserId = ?, @ProjectId = ?
             """
     params = (user_id, project_id)
     conn = Database.connect()
     cursor = conn.cursor()
     results = Database.execute_sproc(query, params, cursor)
     if results['Status'] == 200:
         cursor.commit()
     conn.close()
     return results
Example #4
0
 def join_project(user_id, project_id):
     query = """
             [prj].[AcceptProjectInvite] @UserId = ?, @ProjectId = ?
             """
     params = (user_id, project_id)
     conn = Database.connect()
     cursor = conn.cursor()
     results = Database.execute_sproc(query, params, cursor)
     if results['Status'] == 201:
         cursor.commit()
     conn.close()
     return results
Example #5
0
    def create_dataset_metadata(dataset_id, dataset_name):

        query = f"""
                [metadata].[GetorInsertDataset] @DatasetName = ?, @DataSetId = ?
                """
        params = (dataset_name, dataset_id)
        conn = Database.connect()
        cursor = conn.cursor()
        response = Database.execute_sproc(query, params, cursor)
        if response['Status'] == 201:
            cursor.commit()
        conn.close()
        return response
Example #6
0
    def create_project(user_id, project_info):

        query = """
                [prj].[CreateProject] @Creator = ?, @Name = ?, @Desc = ?, @Public = ?
                """
        params = (user_id, project_info['Name'], project_info['Desc'], project_info['Public'])
        conn = Database.connect()
        cursor = conn.cursor()
        results = Database.execute_sproc(query, params, cursor)
        if results['Status'] == 201:
            cursor.commit()
        conn.close()
        return results
Example #7
0
 def accept_pending_invite(user_id, institution_id):
     pending = Institution.get_all_pending(user_id)
     if institution_id in pending:
         query = f"""
                 [usr].[AcceptInstitutionInvite] ?, ?
                 """
         params = (user_id, institution_id)
         conn = Database.connect()
         cursor = conn.cursor()
         results = Database.execute_sproc(query, params, cursor)
         if results['Status'] == 201:
             cursor.commit()
         conn.close()
         return results
     return {'Status': 400, 'Message': 'This institution has not invited this user'}
Example #8
0
 def member_leave(user_id):
     user = User.get_user_info(user_id)
     if user.get_institution() is not None:
         query = f"""
                     [usr].[RemoveUserFromInstitution] ?, ?
                 """
         params = (user_id, user.get_institution())
         conn = Database.connect()
         cursor = conn.cursor()
         results = Database.execute_sproc(query, params, cursor)
         if results['Status'] == 200:
             cursor.commit()
         conn.close()
         return results
     else:
         return {'Status': 400, 'Message': 'User not part of institution'}
Example #9
0
 def upload_file_metadata(self):
     query = f"""
             [metadata].[InsertFileMetaData] ?,?,?,?,?,?,?,?,?,?,?,?
             """
     params = (self.file_id, self.file_name, self.user_id, self.signal_type, self.species, self.gender,
               self.age, self.target, self.action, self.device, self.dataset_id, self.channel_count)
     print(params)
     conn = Database.connect()
     cursor = conn.cursor()
     results = Database.execute_sproc(query, params, cursor)
     if results['Status'] == 201:
         cursor.commit()
         response = {'Status': results['Status'], 'FileId': self.file_id, "Message": results['Message']}
     else:
         cursor.rollback()
         response = {'Status': results['Status'], 'FileId': self.file_id, "Message": results['Message']}
     conn.close()
     return response
Example #10
0
    def invite_to_project(project_info):
        query = """
                [prj].[InviteUserToProject] @UserId = ?, @ProjectId = ?
                """
        user_id = User.get_user_from_email(project_info['Email'])

        if user_id is not None:
            project_id = project_info['ProjectId']
            params = (user_id, project_id)
            conn = Database.connect()
            cursor = conn.cursor()
            results = Database.execute_sproc(query, params, cursor)
            if results['Status'] == 201:
                cursor.commit()
            conn.close()
        else:
            results = {'Status': 404, 'Message': 'This email does not have a registered account'}
        return results
Example #11
0
 def invite_member(user_id, invitation_info):
     user = User.get_user_info(user_id)
     if user.get_institution() is not None:
         invited_user_id = User.get_user_from_email(invitation_info['Email'])
         if invited_user_id is not None:
             if user.get_institution() not in Institution.get_all_pending(invited_user_id):
                 query = f"""
                             [usr].[InviteUserToInstitution] ?, ?, ?
                         """
                 params = (invited_user_id, user.get_institution(), invitation_info['Role'])
                 conn = Database.connect()
                 cursor = conn.cursor()
                 results = Database.execute_sproc(query, params, cursor)
                 if results['Status'] == 201:
                     cursor.commit()
                 conn.close()
                 return results
             else:
                 return {'Status': 400, 'Message': 'This account has already been invited'}
         else:
             return {'Status': 400, 'Message': 'There is no account associated with this email'}
     else:
         return {'Status': 400, 'Message': 'User not part of institution'}
Example #12
0
 def remove_member(user_id, email):
     user = User.get_user_info(user_id)
     if user.get_institution() is not None:
         institution = Institution.get_institution(user.get_institution())
         if institution.get_owner() == user_id:
             remove_user_id = User.get_user_from_email(email)
             if remove_user_id is not None:
                 query = f"""
                         [usr].[RemoveUserFromInstitution] ?, ?
                         """
                 params = (remove_user_id, user.get_institution())
                 conn = Database.connect()
                 cursor = conn.cursor()
                 results = Database.execute_sproc(query, params, cursor)
                 if results['Status'] == 200:
                     cursor.commit()
                 conn.close()
                 return results
             else:
                 return {'Status': 400, 'Message': 'There is no account associated with this email'}
         else:
             return {'Status': 400, 'Message': 'User is not owner of institution'}
     else:
         return {'Status': 400, 'Message': 'User not part of institution'}