Skip to content

Commit

Permalink
Merge pull request #60 from naxa-developers/revert-59-test/osm-teams
Browse files Browse the repository at this point in the history
Revert "test/osm teams"
  • Loading branch information
royallsilwallz authored Feb 19, 2024
2 parents 4d6fb3f + 9d79714 commit d14a1e0
Show file tree
Hide file tree
Showing 36 changed files with 112 additions and 1,568 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
name: Run yarn test
command: |
cd ${CIRCLE_WORKING_DIRECTORY}/frontend/
CI=true REACT_APP_OSM_TEAMS_CLIENT_ID=boo yarn test -w 1
CI=true yarn test -w 1
CI=true GENERATE_SOURCEMAP=false yarn build
backend-code-check-PEP8:
Expand Down
13 changes: 0 additions & 13 deletions backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ def format_url(endpoint):
scope=EnvironmentConfig.OAUTH_SCOPE,
redirect_uri=EnvironmentConfig.OAUTH_REDIRECT_URI,
)
osm_teams = OAuth2Session(
client_id=EnvironmentConfig.OSM_TEAMS_CLIENT_ID,
scope="openid offline",
)

# Import all models so that they are registered with SQLAlchemy
from backend.models.postgis import * # noqa
Expand Down Expand Up @@ -380,8 +376,6 @@ def add_api_endpoints(app):
SystemAuthenticationEmailAPI,
SystemAuthenticationLoginAPI,
SystemAuthenticationCallbackAPI,
OSMTeamsAuthenticationCallbackAPI,
OSMTeamsAuthenticationAPI,
)
from backend.api.system.applications import SystemApplicationsRestAPI
from backend.api.system.image_upload import SystemImageUploadRestAPI
Expand Down Expand Up @@ -934,16 +928,9 @@ def add_api_endpoints(app):
api.add_resource(
SystemAuthenticationLoginAPI, format_url("system/authentication/login/")
)
api.add_resource(
OSMTeamsAuthenticationAPI, format_url("system/osm-teams-authentication/login/")
)
api.add_resource(
SystemAuthenticationCallbackAPI, format_url("system/authentication/callback/")
)
api.add_resource(
OSMTeamsAuthenticationCallbackAPI,
format_url("system/osm-teams-authentication/callback/"),
)
api.add_resource(
SystemAuthenticationEmailAPI, format_url("system/authentication/email/")
)
Expand Down
92 changes: 1 addition & 91 deletions backend/api/system/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_restful import Resource
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError

from backend import osm, osm_teams
from backend import osm
from backend.config import EnvironmentConfig
from backend.services.users.authentication_service import (
AuthenticationService,
Expand Down Expand Up @@ -42,33 +42,6 @@ def get(self):
return {"auth_url": login_url, "state": state}, 200


class OSMTeamsAuthenticationAPI(Resource):
def get(self):
"""
Returns URL to allow authentication in OSM Teams
---
tags:
- system
produces:
- application/json
parameters:
- in: query
name: redirect_uri
description: Route to redirect user once authenticated
type: string
default: /take/me/here
responses:
200:
description: oauth2 params
"""
state = AuthenticationService.generate_random_state()
osm_teams.state = state
login_url, state = osm_teams.authorization_url(
EnvironmentConfig.OSM_TEAMS_AUTH_URL
)
return {"auth_url": login_url, "state": state}, 200


class SystemAuthenticationCallbackAPI(Resource):
def get(self):
"""
Expand Down Expand Up @@ -152,69 +125,6 @@ def get(self):
return {"Error": "Unable to authenticate", "SubCode": "AuthError"}, 500


class OSMTeamsAuthenticationCallbackAPI(Resource):
def get(self):
"""
Handles the OSM Teams OAuth callback
---
tags:
- system
produces:
- application/json
parameters:
- in: query
name: redirect_uri
description: Route to redirect user once authenticated
type: string
default: /take/me/here
required: false
- in: query
name: code
description: Code obtained after user authorization
type: string
required: true
- in: query
name: email_address
description: Email address to used for email notifications from TM.
type: string
required: false
responses:
302:
description: Redirects to login page, or login failed page
500:
description: A problem occurred authenticating the user
502:
description: A problem occurred negotiating with the OSM API
"""

authorization_code = request.args.get("code", None)
if authorization_code is None:
return {"Subcode": "InvalidData", "Error": "Missing code parameter"}, 500

try:
osm_teams_response = osm_teams.fetch_token(
token_url=EnvironmentConfig.OSM_TEAMS_TOKEN_URL,
client_secret=EnvironmentConfig.OSM_TEAMS_CLIENT_SECRET,
code=authorization_code,
)
except InvalidGrantError:
return {
"Error": "The provided authorization grant is invalid, expired or revoked",
"SubCode": "InvalidGrantError",
}, 400
if osm_teams_response is None:
current_app.logger.critical("Couldn't obtain token from OSM Teams.")
return {
"Subcode": "TokenFetchError",
"Error": "Couldn't fetch token from OSM Teams.",
}, 502

try:
return osm_teams_response, 200
except AuthServiceError:
return {"Error": "Unable to authenticate", "SubCode": "AuthError"}, 500


class SystemAuthenticationEmailAPI(Resource):
def get(self):
"""
Expand Down
5 changes: 0 additions & 5 deletions backend/api/teams/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def patch(self, team_id):
name:
type: string
default: HOT - Mappers
osm_teams_id:
type: integer
logo:
type: string
default: https://tasks.hotosm.org/assets/img/hot-tm-logo.svg
Expand Down Expand Up @@ -320,8 +318,6 @@ def post(self):
organisation_id:
type: integer
default: 1
osm_teams_id:
type: integer
description:
type: string
visibility:
Expand All @@ -335,7 +331,6 @@ def post(self):
- "ANY"
- "BY_REQUEST"
- "BY_INVITE"
- "OSM_TEAMS"
responses:
201:
description: Team created successfully
Expand Down
11 changes: 0 additions & 11 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,6 @@ class EnvironmentConfig:
# Sentry backend DSN
SENTRY_BACKEND_DSN = os.getenv("TM_SENTRY_BACKEND_DSN", None)

# OSM Teams
OSM_TEAMS_CLIENT_ID = os.getenv("OSM_TEAMS_CLIENT_ID", None)
OSM_TEAMS_CLIENT_SECRET = os.getenv("OSM_TEAMS_CLIENT_SECRET", None)
OSM_TEAMS_AUTH_DOMAIN = os.getenv("OSM_TEAMS_AUTH_DOMAIN", None)
OSM_TEAMS_TOKEN_DOMAIN = os.getenv("OSM_TEAMS_TOKEN_DOMAIN", OSM_TEAMS_AUTH_DOMAIN)
OSM_TEAMS_AUTH_PATH = os.getenv("OSM_TEAMS_AUTH_PATH", "/hyauth/oauth2/auth")
OSM_TEAMS_TOKEN_PATH = os.getenv("OSM_TEAMS_TOKEN_PATH", "/hyauth/oauth2/token")
OSM_TEAMS_AUTH_URL = f"{OSM_TEAMS_AUTH_DOMAIN}{OSM_TEAMS_AUTH_PATH}"
OSM_TEAMS_TOKEN_URL = f"{OSM_TEAMS_TOKEN_DOMAIN}{OSM_TEAMS_TOKEN_PATH}"
OSM_TEAMS_API_URL = os.getenv("OSM_TEAMS_API_URL", None)


class TestEnvironmentConfig(EnvironmentConfig):
POSTGRES_TEST_DB = os.getenv("POSTGRES_TEST_DB", None)
Expand Down
5 changes: 0 additions & 5 deletions backend/models/dtos/team_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def validate_team_join_method(value):
f"{TeamJoinMethod.ANY.name}, "
f"{TeamJoinMethod.BY_INVITE.name}, "
f"{TeamJoinMethod.BY_REQUEST.name}"
f"{TeamJoinMethod.OSM_TEAMS.name}"
)


Expand Down Expand Up @@ -93,7 +92,6 @@ def __init__(self):
""" Describes JSON model for a team """
team_id = IntType(serialized_name="teamId")
organisation_id = IntType(required=True)
osm_teams_id = IntType(required=False)
organisation = StringType(required=True)
organisation_slug = StringType(serialized_name="organisationSlug")
name = StringType(required=True)
Expand Down Expand Up @@ -133,7 +131,6 @@ class TeamDTO(Model):
members = ListType(ModelType(TeamMembersDTO))
members_count = IntType(serialized_name="membersCount", required=False)
managers_count = IntType(serialized_name="managersCount", required=False)
osm_teams_id = IntType(required=False)


class TeamsListDTO(Model):
Expand All @@ -153,7 +150,6 @@ class NewTeamDTO(Model):
creator = LongType(required=True)
organisation_id = IntType(required=True)
name = StringType(required=True)
osm_teams_id = IntType()
description = StringType()
join_method = StringType(
required=True,
Expand All @@ -170,7 +166,6 @@ class UpdateTeamDTO(Model):

creator = LongType()
team_id = IntType()
osm_teams_id = IntType()
organisation = StringType()
organisation_id = IntType()
name = StringType()
Expand Down
1 change: 0 additions & 1 deletion backend/models/postgis/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class TeamJoinMethod(Enum):
ANY = 0
BY_REQUEST = 1
BY_INVITE = 2
OSM_TEAMS = 3


class TeamRoles(Enum):
Expand Down
4 changes: 0 additions & 4 deletions backend/models/postgis/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Team(db.Model):
visibility = db.Column(
db.Integer, default=TeamVisibility.PUBLIC.value, nullable=False
)
osm_teams_id = db.Column(db.BigInteger, nullable=True)

organisation = db.relationship(Organisation, backref="teams")

Expand All @@ -96,7 +95,6 @@ def create_from_dto(cls, new_team_dto: NewTeamDTO):
new_team.description = new_team_dto.description
new_team.join_method = TeamJoinMethod[new_team_dto.join_method].value
new_team.visibility = TeamVisibility[new_team_dto.visibility].value
new_team.osm_teams_id = new_team_dto.osm_teams_id

org = Organisation.get(new_team_dto.organisation_id)
new_team.organisation = org
Expand Down Expand Up @@ -199,7 +197,6 @@ def as_dto(self):
team_dto.name = self.name
team_dto.organisation = self.organisation.name
team_dto.organisation_id = self.organisation.id
team_dto.osm_teams_id = self.osm_teams_id
team_dto.logo = self.organisation.logo
team_dto.visibility = TeamVisibility(self.visibility).name
return team_dto
Expand All @@ -210,7 +207,6 @@ def as_dto_inside_org(self):
team_dto.team_id = self.id
team_dto.name = self.name
team_dto.description = self.description
team_dto.osm_teams_id = self.osm_teams_id
team_dto.join_method = TeamJoinMethod(self.join_method).name
team_dto.members = self._get_team_members()
team_dto.visibility = TeamVisibility(self.visibility).name
Expand Down
2 changes: 0 additions & 2 deletions backend/services/team_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ def get_all_teams(search_dto: TeamSearchDTO) -> TeamsListDTO:
team_dto.join_method = TeamJoinMethod(team.join_method).name
team_dto.visibility = TeamVisibility(team.visibility).name
team_dto.description = team.description
team_dto.osm_teams_id = team.osm_teams_id
team_dto.logo = team.organisation.logo
team_dto.organisation = team.organisation.name
team_dto.organisation_id = team.organisation.id
Expand Down Expand Up @@ -346,7 +345,6 @@ def get_team_as_dto(
team_dto.join_method = TeamJoinMethod(team.join_method).name
team_dto.visibility = TeamVisibility(team.visibility).name
team_dto.description = team.description
team_dto.osm_teams_id = team.osm_teams_id
team_dto.logo = team.organisation.logo
team_dto.organisation = team.organisation.name
team_dto.organisation_id = team.organisation.id
Expand Down
10 changes: 0 additions & 10 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ TM_DEFAULT_LOCALE=en
# Underpass API URL (for project live monitoring feature)
UNDERPASS_URL=https://underpass.hotosm.org

# OSM Teams
OSM_TEAMS_AUTH_DOMAIN='https://auth.mapping.team'
OSM_TEAMS_AUTH_PATH='/hyauth/oauth2/auth'
# The TOKEN domain only needs to be set if some network restriction blocks getting a token from the AUTH domain
# If it is not configured, TM will use the AUTH domain.
OSM_TEAMS_TOKEN_DOMAIN='https://auth.mapping.team'
OSM_TEAMS_TOKEN_PATH='/hyauth/oauth2/token'
OSM_TEAMS_API_URL='https://mapping.team'
# OSM_TEAMS_CLIENT_ID=foo
# OSM_TEAMS_CLIENT_SECRET=foo

#EXPORT TOOL Integration with 0(Disable) and 1(Enable) and S3 URL for Export Tool
#EXPORT_TOOL_S3_URL=https://foorawdataapi.s3.amazonaws.com
Expand Down
5 changes: 0 additions & 5 deletions frontend/.env.expand
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,5 @@ REACT_APP_SENTRY_FRONTEND_DSN=$TM_SENTRY_FRONTEND_DSN
REACT_APP_ENVIRONMENT=$TM_ENVIRONMENT
REACT_APP_TM_DEFAULT_CHANGESET_COMMENT=$TM_DEFAULT_CHANGESET_COMMENT
REACT_APP_RAPID_EDITOR_URL=$RAPID_EDITOR_URL
<<<<<<< HEAD
REACT_APP_OSM_TEAMS_API_URL=$OSM_TEAMS_API_URL
REACT_APP_OSM_TEAMS_CLIENT_ID=$OSM_TEAMS_CLIENT_ID
=======
REACT_APP_EXPORT_TOOL_S3_URL=$EXPORT_TOOL_S3_URL
REACT_APP_ENABLE_EXPORT_TOOL=$ENABLE_EXPORT_TOOL
>>>>>>> 0331beb6c7c059e04de77864c956f29eae4cafa1
9 changes: 1 addition & 8 deletions frontend/src/components/formInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import { formatCountryList } from '../utils/countries';
import { fetchLocalJSONAPI } from '../network/genericJSONRequest';
import { CheckIcon, SearchIcon, CloseIcon } from './svgIcons';

export const RadioField = ({
name,
value,
className,
required = false,
disabled = false,
}: Object) => (
export const RadioField = ({ name, value, className, required = false }: Object) => (
<Field
name={name}
component="input"
Expand All @@ -25,7 +19,6 @@ export const RadioField = ({
className || ''
}`}
required={required}
disabled={disabled}
/>
);

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/svgIcons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ export { CutIcon } from './cut';
export { FileImportIcon } from './fileImport';
export { CalendarIcon } from './calendar';
export { CommentIcon } from './comment';
export { UserGroupIcon } from './user-group';
export { DownloadIcon } from './download';
16 changes: 0 additions & 16 deletions frontend/src/components/svgIcons/user-group.js

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/components/teamsAndOrgs/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export function JoinMethodBox(props) {
ANY: 'anyoneCanJoin',
BY_REQUEST: 'byRequest',
BY_INVITE: 'byInvite',
OSM_TEAMS: 'OSMTeams',
};
return (
<div className={`tc br1 f7 ttu ba red b--red ${props.className}`}>
Expand Down
Loading

0 comments on commit d14a1e0

Please sign in to comment.