Example #1
0
def is_user_admin(user, organization=None):
  if organization and organization != user.organization:
    return False

  org_config = config.get_organization_config(user.organization)

  return user.email in org_config.get('admins', []) if org_config else False
Example #2
0
    def test_get_organization_config__from_dedicated_file(self):
        with patch('builtins.open',
                   mock_open(
                       read_data='admins:\n - [email protected]')) as mocked_open:
            self.assertEqual({'admins': ['*****@*****.**']},
                             config.get_organization_config('googs.com'))

            self.assertTrue(
                mocked_open.call_args[0][0].endswith('googs.com.yaml'))
Example #3
0
def is_user_admin(user, organization=None):
  if organization and organization != user.organization:
    return False

  admin_ids = get_admin_ids(user.organization)
  if admin_ids is not None:
    return user.id in admin_ids

  org_config = config.get_organization_config(user.organization)

  return user.email in org_config.get('admins', []) if org_config else False
Example #4
0
def check_namespace(user_org, shortpath):
  shortpath_parts = shortpath.split('/', 1)
  if len(shortpath_parts) > 1:
    org_namespaces = config.get_organization_config(user_org).get('namespaces')
    if org_namespaces:
      shortpath_start, shortpath_remainder = shortpath_parts

      if shortpath_start in org_namespaces:
        return shortpath_start, shortpath_remainder

  return config.get_default_namespace(user_org), shortpath
Example #5
0
def get_organization_id_for_email(email_address):
  if email_address in TEST_ORGANIZATION_EMAIL_ADDRESSES:
    return TEST_ORGANIZATION_ID

  email_domain = email_address.split('@')[1].strip()
  if email_domain in GENERIC_EMAIL_DOMAINS:
    # links for generic emails are siloed to just that email
    return email_address.strip()

  org_config = config.get_organization_config(email_domain)

  return org_config.get('alias_to', email_domain) if org_config else email_domain
Example #6
0
def check_namespaces(organization, namespace, shortpath):
  org_namespaces = config.get_organization_config(organization).get('namespaces', [])
  default_namespace = config.get_default_namespace(organization)

  if namespace != default_namespace and namespace not in org_namespaces:
    raise LinkCreationException('"%s" is not a valid link prefix for your organization' % (namespace))

  # If an organization has a namespace of, for example, "eng", go/eng can be created, but go/eng/%s would conflict
  # with eng/something, as {base}/eng/something is how users without an extension installed can still easily
  # access links in the "eng" namespace.
  if namespace == default_namespace:
    shortpath_parts = shortpath.split('/')
    if len(shortpath_parts) > 1 and shortpath_parts[0] in org_namespaces:
      raise LinkCreationException('"%s" is a reserved prefix for your organization' % (shortpath_parts[0]))
Example #7
0
def home():
    if not current_user.is_authenticated:
        return redirect('https://www.trot.to' if request.host ==
                        'trot.to' else '/_/auth/login')

    template = JINJA_ENVIRONMENT.get_template('index.html')

    namespaces = config.get_organization_config(current_user.organization).get(
        'namespaces', [])

    return template.render({
        'csrf_token': generate_csrf(),
        'namespaces': json.dumps(namespaces)
    })
Example #8
0
def home():
  if not current_user.is_authenticated:
    return redirect('https://www.trot.to'
                    if request.host == 'trot.to'
                    else '/_/auth/login')

  from modules.organizations.helpers import get_org_settings

  template = JINJA_ENVIRONMENT.get_template('index.html')

  namespaces = config.get_organization_config(current_user.organization).get('namespaces', [])
  admin_links = get_org_settings(current_user.organization).get('admin_links', [])

  return template.render({'csrf_token': generate_csrf(),
                          'default_namespace': config.get_default_namespace(current_user.organization),
                          'namespaces': json.dumps(namespaces),
                          'admin_links': json.dumps(admin_links)})
Example #9
0
def layout_config():
    _config = (config.get_organization_config(current_user.organization)
               if current_user.is_authenticated else config.get_config())

    return f"window._trotto = window._trotto || {{}}; window._trotto.layout = {json.dumps(_config.get('layout', {}))};"
Example #10
0
def is_user_admin(user):
    org_config = config.get_organization_config(user.organization)

    return user.email in org_config.get('admins', []) if org_config else False
Example #11
0
 def test_get_organization_config__from_general_config_file__no_org_config(self, _):
   self.assertEqual({},
                    config.get_organization_config('googsetc.com'))
Example #12
0
 def test_get_organization_config__from_general_config_file(self, _):
   self.assertEqual({'admins': ['*****@*****.**']},
                    config.get_organization_config('googsetc.com'))