Ejemplo n.º 1
0
    def add_project_access(self, access_token, project_id, access_type, language, measurement_sys, gps_format, map_type, message, emails):
        user = self.repository.get_user_by_access_token(access_token)
        user_id = user.get("user_id")
        existing_project_accesses = self.repository.get_project_access_by_project_id(project_id)

        if (len(emails) == 0 and access_type != "PUBLIC"):
            raise barrister.RpcException(1002, "TRANSLATE: Must specify at least one email address if access_type is not PUBLIC")
        elif (access_type == "OWNER"):
            raise barrister.RpcException(1004, "Can't add OWNER ProjectAccess")
        else:
            project_access = []
            access_type = access_type
            emails_validated = []
            link = "http://%s" % (self.env_domain)
            to_email = "*****@*****.**"

            if (not access_type == "PUBLIC"):
                emails_validated = self.__strip_bad_emails(emails)
                for i in range(len(emails_validated)):
                    if (not emails_validated[i] == user["email"]):
                        # wipe access by emails
                        for id in filter(lambda x: x['email'] == emails_validated[i], existing_project_accesses):
                          self.repository.delete_project_access(id)

                        # get the user_id, if we have it in our system
                        user2 = self.repository.get_user_by_email(emails_validated[i])
                        if (user2 is None):
                            user2 = dict(user_id=None)

                        # add the new access rule
                        new_id = self.repository.create_project_access(project_id, access_type, user2['user_id'], emails_validated[i])

                        project_access.append(dict(
                            project_access_id = new_id,
                            project_id = project_id,
                            email=emails_validated[i],
                            access_type=access_type
                        ))
            else:
                link = "http://%s/#/public/%s/%s/%s/%s/%s" % (self.env_domain, language, gps_format, measurement_sys, project_id, map_type)
                to_email = user["email"]

                # wipe previous public-access entry, if exists
                for id in filter(lambda x: x['access_type'] == 'PUBLIC', existing_project_accesses):
                  self.repository.delete_project_access(id)

                # add the new access rule
                new_id = self.repository.create_project_access(project_id, 'PUBLIC')
                project_access.append(dict(
                    project_access_id = new_id,
                    project_id = project_id,
                    access_type=access_type,
                    link = link
                ))

            message = u"""%s:\n\r%s\n\r%s""" % (user["name"], message, link)
            self.mail_service.mail(to_email, [], emails_validated, "SimpleMappingSystem.com", message)
            return project_access
Ejemplo n.º 2
0
 def updatePage(self, page):
     existing = self.getPage(page["id"])
     if not existing:
         raise barrister.RpcException(40, "No page exists with id: %s" % page["id"])
     elif existing["version"] != page["version"]:
         raise barrister.RpcException(30, "Version is out of date")
     else:
         version = existing["version"] + 1
         page["version"]     = version
         page["createdTime"] = existing["createdTime"]
         page["updatedTime"] = now_millis()
         self.pagesById[page["id"]] = page
         return version
 def wrapper(*args, **kwargs):
     try:
         return function(*args, **kwargs)
     except Exception, e:
         exc_type = sys.exc_info()[0]
         if exc_type in list(exceptions):
             raise barrister.RpcException(errors[exc_type], str(e))
Ejemplo n.º 4
0
    def add_position(self, access_token, project_id, properties):
        user_id = self.repository.get_user_by_access_token(access_token)["user_id"]

        if (not self.__has_required_fields(properties)):
            raise barrister.RpcException(1004, "Must include core fields")

        if (not self.__has_valid_field_names(access_token, project_id, properties)):
            raise barrister.RpcException(1004, "Can not include properties with names that don't correspond to fields for this project")

        if (not self.__has_core_field_values(properties)):
            raise barrister.RpcException(1002, "Must include values for core fields")

        new_position_id = self.repository.create_position(user_id, project_id)
        self.__create_position_properties(project_id, new_position_id, properties)

        return self.get_position_by_id(new_position_id)
Ejemplo n.º 5
0
    def delete_project_access(self, access_token, project_access_id):
        existing = self.repository.get_project_access_by_id(project_access_id)

        if (len(existing) > 0 and existing[0]["access_type"] == "OWNER"):
            raise barrister.RpcException(1004, "Can't revoke OWNER ProjectAccess")

        return self.repository.delete_project_access(project_access_id)
Ejemplo n.º 6
0
 def deletePage(self, id, version):
     existing = self.getPage(id)
     if existing:
         if existing["version"] == version:
             del self.pagesById[id]
             return True
         else:
             raise barrister.RpcException(30, "Version is out of date")
     else:
         return False
Ejemplo n.º 7
0
    if batch:
        cur_client = batch

    iface, func, params, exp_status, exp_resp = line.split("|")
    p = json.loads(params)

    svc = getattr(cur_client, iface)
    fn = getattr(svc, func)
    if isinstance(p, list):
        c = lambda: fn(*p)
    else:
        c = lambda: fn(p)

    if batch:
        c()
    else:
        result = None
        error = None
        try:
            result = c()
        except barrister.RpcException as e:
            error = e
        except e:
            error = barrister.RpcException(-1, str(sys.exc_info()))
        get_and_log_result(iface, func, params, result, error)

    line = f.readline()

f.close()
out.close()
Ejemplo n.º 8
0
 def echo(self, s):
     if s == "err":
         raise barrister.RpcException(99, "Error!")
     else:
         return s
Ejemplo n.º 9
0
 def _check_contact_owner(self, contact):
     username = self._get_username()
     if not username or username != contact["username"]:
         raise barrister.RpcException(4000, "Permission Denied for user")