Exemplo n.º 1
0
 def join_workspace(workspace_url):
     try:
         w = find_workspace(workspace_url)
     except Exception as e:
         sublime.error_message('Error: %s' % str_e(e))
         return False
     if not w:
         return False
     msg.debug('workspace: %s', json.dumps(w.body))
     # if self.api_args:
     anon_perms = w.body.get('perms', {}).get('AnonymousUser', [])
     new_anon_perms = self.api_args.get('perms').get(
         'AnonymousUser', [])
     # TODO: warn user about making a private workspace public
     if set(anon_perms) != set(new_anon_perms):
         msg.debug(str(anon_perms), str(new_anon_perms))
         w.body['perms']['AnonymousUser'] = new_anon_perms
         response = api.update_workspace(workspace_url, w.body)
         msg.debug(str(response.body))
     utils.add_workspace_to_persistent_json(w.body['owner'],
                                            w.body['name'],
                                            workspace_url, dir_to_share)
     self.window.run_command('floobits_join_workspace',
                             {'workspace_url': workspace_url})
     return True
Exemplo n.º 2
0
    def prejoin_workspace(self, workspace_url, dir_to_share, api_args):
        try:
            result = utils.parse_url(workspace_url)
        except Exception as e:
            msg.error(str_e(e))
            return False

        host = result.get('host')
        if not api.get_basic_auth(host):
            raise ValueError(
                'No auth credentials for %s. Please add a username and secret for %s in your ~/.floorc.json'
                % (host, host))

        try:
            w = api.get_workspace_by_url(workspace_url)
        except Exception as e:
            editor.error_message('Error opening url %s: %s' %
                                 (workspace_url, str_e(e)))
            return False

        if w.code >= 400:
            try:
                d = utils.get_persistent_data()
                try:
                    del d['workspaces'][result['owner']][result['name']]
                except Exception:
                    pass
                try:
                    del d['recent_workspaces'][workspace_url]
                except Exception:
                    pass
                utils.update_persistent_data(d)
            except Exception as e:
                msg.debug(str_e(e))
            return False

        msg.debug('workspace: ', json.dumps(w.body))
        anon_perms = w.body.get('perms', {}).get('AnonymousUser', [])
        msg.debug('api args: ', api_args)
        new_anon_perms = api_args.get('perms', {}).get('AnonymousUser', [])
        # TODO: prompt/alert user if going from private to public
        if set(anon_perms) != set(new_anon_perms):
            msg.debug(str(anon_perms), str(new_anon_perms))
            w.body['perms']['AnonymousUser'] = new_anon_perms
            response = api.update_workspace(workspace_url, w.body)
            msg.debug(str(response.body))
        utils.add_workspace_to_persistent_json(w.body['owner'], w.body['name'],
                                               workspace_url, dir_to_share)
        return result
Exemplo n.º 3
0
    def prejoin_workspace(self, workspace_url, dir_to_share, api_args):
        try:
            result = utils.parse_url(workspace_url)
        except Exception as e:
            msg.error(str_e(e))
            return False

        host = result.get("host")
        if not api.get_basic_auth(host):
            raise ValueError(
                "No auth credentials for %s. Please add a username and secret for %s in your ~/.floorc.json"
                % (host, host)
            )

        try:
            w = api.get_workspace_by_url(workspace_url)
        except Exception as e:
            editor.error_message("Error opening url %s: %s" % (workspace_url, str_e(e)))
            return False

        if w.code >= 400:
            try:
                d = utils.get_persistent_data()
                try:
                    del d["workspaces"][result["owner"]][result["name"]]
                except Exception:
                    pass
                try:
                    del d["recent_workspaces"][workspace_url]
                except Exception:
                    pass
                utils.update_persistent_data(d)
            except Exception as e:
                msg.debug(str_e(e))
            return False

        msg.debug("workspace: ", json.dumps(w.body))
        anon_perms = w.body.get("perms", {}).get("AnonymousUser", [])
        msg.debug("api args: ", api_args)
        new_anon_perms = api_args.get("perms", {}).get("AnonymousUser", [])
        # TODO: prompt/alert user if going from private to public
        if set(anon_perms) != set(new_anon_perms):
            msg.debug(str(anon_perms), str(new_anon_perms))
            w.body["perms"]["AnonymousUser"] = new_anon_perms
            response = api.update_workspace(workspace_url, w.body)
            msg.debug(str(response.body))
        utils.add_workspace_to_persistent_json(w.body["owner"], w.body["name"], workspace_url, dir_to_share)
        return result
 def join_workspace(workspace_url):
     try:
         w = find_workspace(workspace_url)
     except Exception as e:
         sublime.error_message('Error: %s' % str_e(e))
         return False
     if not w:
         return False
     msg.debug('workspace: %s', json.dumps(w.body))
     # if self.api_args:
     anon_perms = w.body.get('perms', {}).get('AnonymousUser', [])
     new_anon_perms = self.api_args.get('perms').get('AnonymousUser', [])
     # TODO: warn user about making a private workspace public
     if set(anon_perms) != set(new_anon_perms):
         msg.debug(str(anon_perms), str(new_anon_perms))
         w.body['perms']['AnonymousUser'] = new_anon_perms
         response = api.update_workspace(workspace_url, w.body)
         msg.debug(str(response.body))
     utils.add_workspace_to_persistent_json(w.body['owner'], w.body['name'], workspace_url, dir_to_share)
     self.window.run_command('floobits_join_workspace', {'workspace_url': workspace_url})
     return True