Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Display names #169

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/models/dtos/mapping_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TaskHistoryDTO(Model):
action_by = StringType(serialized_name="actionBy")
picture_url = StringType(serialized_name="pictureUrl")
issues = ListType(ModelType(TaskMappingIssueDTO))
name = StringType(serialized_name='name')


class TaskStatusDTO(Model):
Expand All @@ -70,6 +71,7 @@ class TaskStatusDTO(Model):
task_status = StringType(serialized_name="taskStatus")
action_date = UTCDateTimeType(serialized_name="actionDate")
action_by = StringType(serialized_name="actionBy")
name = StringType()


class TaskDTO(Model):
Expand Down
1 change: 1 addition & 0 deletions backend/models/dtos/message_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ChatMessageDTO(Model):
picture_url = StringType(default=None, serialized_name="pictureUrl")
timestamp = UTCDateTimeType()
username = StringType()
name = StringType()


class ProjectChatDTO(Model):
Expand Down
1 change: 1 addition & 0 deletions backend/models/dtos/organisation_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OrganisationManagerDTO(Model):

username = StringType(required=True)
picture_url = StringType(serialized_name="pictureUrl")
name = StringType()


class OrganisationTeamsDTO(Model):
Expand Down
1 change: 1 addition & 0 deletions backend/models/dtos/project_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class ProjectDTO(Model):
created = UTCDateTimeType()
last_updated = UTCDateTimeType(serialized_name="lastUpdated")
author = StringType()
name = StringType()
active_mappers = IntType(serialized_name="activeMappers")
percent_mapped = IntType(serialized_name="percentMapped")
percent_validated = IntType(serialized_name="percentValidated")
Expand Down
1 change: 1 addition & 0 deletions backend/models/dtos/team_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TeamMembersDTO(Model):
function = StringType(required=True, validators=[validate_team_member_function])
active = StringType()
picture_url = StringType(serialized_name="pictureUrl")
name = StringType()


class TeamProjectDTO(Model):
Expand Down
2 changes: 2 additions & 0 deletions backend/models/dtos/user_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class UserDTO(Model):
is_email_verified = EmailType(
serialized_name="isEmailVerified", serialize_when_none=False
)

is_expert = BooleanType(serialized_name="isExpert", serialize_when_none=False)
twitter_id = StringType(serialized_name="twitterId")
facebook_id = StringType(serialized_name="facebookId")
Expand Down Expand Up @@ -199,6 +200,7 @@ class ListedUser(Model):
role = StringType()
mapping_level = StringType(serialized_name="mappingLevel")
picture_url = StringType(serialized_name="pictureUrl")
name = StringType()


class UserRegisterEmailDTO(Model):
Expand Down
1 change: 1 addition & 0 deletions backend/models/postgis/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def as_dto(self, omit_managers=False):

for manager in self.managers:
org_manager_dto = OrganisationManagerDTO()
org_manager_dto.name = manager.name
org_manager_dto.username = manager.username
org_manager_dto.picture_url = manager.picture_url
organisation_dto.managers.append(org_manager_dto)
Expand Down
1 change: 1 addition & 0 deletions backend/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ def _get_project_and_base_dto(self):
base_dto.created = self.created
base_dto.last_updated = self.last_updated
base_dto.author = User.get_by_id(self.author_id).username
base_dto.name = User.get_by_id(self.author_id).name
base_dto.active_mappers = Project.get_active_mappers(self.id)
base_dto.task_creation_mode = TaskCreationMode(self.task_creation_mode).name
base_dto.percent_mapped = Project.calculate_tasks_percent(
Expand Down
2 changes: 1 addition & 1 deletion backend/models/postgis/project_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_messages(project_id: int, page: int, per_page: int = 20) -> ProjectChatD
chat_dto.username = message.posted_by.username
chat_dto.picture_url = message.posted_by.picture_url
chat_dto.timestamp = message.time_stamp

chat_dto.name = message.posted_by.name
dto.chat.append(chat_dto)

dto.pagination = Pagination(project_messages)
Expand Down
13 changes: 4 additions & 9 deletions backend/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class TaskAction(Enum):
COMMENT = 4
AUTO_UNLOCKED_FOR_MAPPING = 5
AUTO_UNLOCKED_FOR_VALIDATION = 6


class TaskInvalidationHistory(db.Model):
""" Describes the most recent history of task invalidation and subsequent validation """

Expand Down Expand Up @@ -197,7 +195,6 @@ class TaskHistory(db.Model):
invalidation_history = db.relationship(
TaskInvalidationHistory, lazy="dynamic", cascade="all"
)

actioned_by = db.relationship(User)
task_mapping_issues = db.relationship(TaskMappingIssue, cascade="all")

Expand Down Expand Up @@ -478,7 +475,6 @@ def get_last_mapped_action(project_id: int, task_id: int):
.first()
)


class Task(db.Model):
""" Describes an individual mapping Task """

Expand Down Expand Up @@ -506,7 +502,6 @@ class Task(db.Model):
validated_by = db.Column(
db.BigInteger, db.ForeignKey("users.id", name="fk_users_validator"), index=True
)

# Mapped objects
task_history = db.relationship(
TaskHistory, cascade="all", order_by=desc(TaskHistory.id)
Expand Down Expand Up @@ -677,7 +672,6 @@ def set_task_history(
TaskAction.AUTO_UNLOCKED_FOR_VALIDATION,
]:
history.set_auto_unlock_action(action)

if mapping_issues is not None:
history.task_mapping_issues = mapping_issues

Expand Down Expand Up @@ -777,7 +771,6 @@ def unlock_task(
)
self.mapped_by = None
self.validated_by = None

if not undo:
# Using a slightly evil side effect of Actions and Statuses having the same name here :)
TaskHistory.update_task_locked_with_duration(
Expand Down Expand Up @@ -935,7 +928,6 @@ def get_tasks_as_geojson_feature_collection_no_geom(project_id):
taskIsSquare=task.is_square,
taskStatus=TaskStatus(task.task_status).name,
)

feature = geojson.Feature(properties=task_properties)
tasks_features.append(feature)

Expand Down Expand Up @@ -1021,6 +1013,9 @@ def as_dto_with_instructions(self, preferred_locale: str = "en") -> TaskDTO:
history.action = action.action
history.action_text = action.action_text
history.action_date = action.action_date
history.name = (
action.actioned_by.name if action.actioned_by else None
)
history.action_by = (
action.actioned_by.username if action.actioned_by else None
)
Expand Down Expand Up @@ -1116,4 +1111,4 @@ def get_locked_tasks_details_for_user(user_id: int):
tasks = Task.query.filter_by(locked_by=user_id)
locked_tasks = [task for task in tasks]

return locked_tasks
return locked_tasks
1 change: 1 addition & 0 deletions backend/models/postgis/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def as_dto_team_member(self, member) -> TeamMembersDTO:
member_dto = TeamMembersDTO()
user = User.get_by_id(member.user_id)
member_function = TeamMemberFunctions(member.function).name
member_dto.name = user.name
member_dto.username = user.username
member_dto.function = member_function
member_dto.picture_url = user.picture_url
Expand Down
19 changes: 15 additions & 4 deletions backend/models/postgis/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ def get_all_users(query: UserSearchQuery) -> UserSearchDTO:

# Base query that applies to all searches
base = db.session.query(
User.id, User.username, User.mapping_level, User.role, User.picture_url
User.id, User.username, User.mapping_level, User.role, User.picture_url, User.name
)

# Add filter to query as required
if query.mapping_level:
mapping_levels = query.mapping_level.split(",")
Expand All @@ -151,7 +150,11 @@ def get_all_users(query: UserSearchQuery) -> UserSearchDTO:
]
base = base.filter(User.mapping_level.in_(mapping_level_array))
if query.username:
base = base.filter(User.username.ilike(query.username.lower() + "%"))
base_query = base.filter(User.username.ilike(query.username.lower() + "%")).all()
if len(base_query):
base = base.filter(User.username.ilike(query.username.lower() + "%"))
else:
base = base.filter(User.name.ilike(query.username.lower() + "%"))

if query.role:
roles = query.role.split(",")
Expand All @@ -168,7 +171,7 @@ def get_all_users(query: UserSearchQuery) -> UserSearchDTO:
listed_user.username = result.username
listed_user.picture_url = result.picture_url
listed_user.role = UserRole(result.role).name

listed_user.name = result.name
dto.users.append(listed_user)

dto.pagination = Pagination(results)
Expand Down Expand Up @@ -390,6 +393,14 @@ def create_or_update_interests(self, interests_ids):
self.interests.extend(objs)
db.session.commit()

def display_name(user_id):
name = db.session.query(User.name).filter(User.id==user_id).all()
username = db.session.query(User.username).filter(User.id==user_id).all()
if user_id:
if len(name):
return name[0]
else:
return username[0]

class UserEmail(db.Model):
__tablename__ = "users_with_email"
Expand Down
4 changes: 4 additions & 0 deletions backend/services/stats_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def get_latest_activity(project_id: int, page: int) -> ProjectActivityDTO:
TaskHistory.action,
TaskHistory.action_date,
TaskHistory.action_text,
TaskHistory.name,
User.username,
)
.join(User)
Expand All @@ -145,6 +146,7 @@ def get_latest_activity(project_id: int, page: int) -> ProjectActivityDTO:
history.action_text = item.action_text
history.action_date = item.action_date
history.action_by = item.username
history.name = item.name
activity_dto.activity.append(history)

activity_dto.pagination = Pagination(results)
Expand Down Expand Up @@ -217,6 +219,7 @@ def get_last_activity(project_id: int) -> ProjectLastActivityDTO:
sq.c.action_date,
sq_statuses.c.task_status,
User.username,
User.name,
)
.outerjoin(sq, sq.c.task_id == sq_statuses.c.id)
.outerjoin(User, User.id == sq.c.user_id)
Expand All @@ -232,6 +235,7 @@ def get_last_activity(project_id: int) -> ProjectLastActivityDTO:
task_status=TaskStatus(r.task_status).name,
action_date=r.action_date,
action_by=r.username,
name=r.name,
)
)
for r in results
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/projectDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export const ProjectDetail = (props) => {
const h2Classes = 'pl4 f2 fw6 mt2 mb3 ttu barlow-condensed blue-dark';
const userLink = (
<Link to={`/users/${props.project.author}`} className="link blue-dark underline">
{props.project.author}
{props.project.name?(props.project.name):(props.project.author)}

</Link>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const QuestionsAndComments = ({ projectId }) => {
};

function CommentList({ comments }: Object) {


return (
<div className="pt3">
{comments.map((comment, n) => (
Expand All @@ -109,6 +111,7 @@ function CommentList({ comments }: Object) {
<div className="fl">
{comment.pictureUrl === null ? null : (
<UserAvatar
name={comment.name}
username={comment.username}
picture={comment.pictureUrl}
colorClasses="white bg-blue-grey"
Expand All @@ -118,7 +121,7 @@ function CommentList({ comments }: Object) {
<div className="fl ml3">
<p className="b ma0">
<a href={`/users/${comment.username}`} className="blue-dark b underline">
{comment.username}
{comment.name ? (comment.name):(comment.username)}
</a>
</p>
<span className="blue-grey f6">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/taskSelection/contributions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Contributor({ user, activeUser, activeStatus, displayTasks }: Object) {
colorClasses="white bg-blue-grey"
/>
<Link className="blue-dark mr2 link" to={`/users/${user.username}`}>
{user.username}
{user.name?(user.name):(user.username)}
</Link>
</span>
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/taskSelection/taskList.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function TaskItem({
<span className="blue-grey">
<FormattedMessage
{...messages.taskLastUpdate}
values={{ user: <span className="b blue-grey">{data.actionBy}</span> }}
values={{ user: <span className="b blue-grey">{data.name ? (data.name):(data.actionBy)}</span> }}
/>{' '}
<RelativeTimeWithUnit date={data.actionDate} />
</span>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/teamsAndOrgs/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function Members({
{members.map((user, n) => (
<UserAvatar
key={n}
name={user.name}
username={user.username}
picture={user.pictureUrl}
size="large"
Expand Down Expand Up @@ -145,6 +146,7 @@ export function JoinRequests({ requests, teamId, addMembers, updateRequests }: O
<div className="cf db pt2" key={n}>
<div className="fl pt1">
<UserAvatar
name={user.name}
username={user.username}
picture={user.pictureUrl}
colorClasses="white bg-blue-grey"
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/teamsAndOrgs/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export function Teams({ teams, viewAllQuery, showAddButton = false, isReady }: O
}

export function TeamCard({ team, managementView }: Object) {


return (
<Link
to={managementView ? `/manage/teams/${team.teamId}/` : `/teams/${team.teamId}/membership/`}
Expand Down Expand Up @@ -257,6 +259,7 @@ export function TeamForm(props) {
export function TeamSideBar({ team, members, managers, requestedToJoin }: Object) {
const [isUserTeamManager] = useEditTeamAllowed(team);


return (
<ReactPlaceholder
showLoadingAnimation={true}
Expand Down Expand Up @@ -306,6 +309,7 @@ export function TeamSideBar({ team, members, managers, requestedToJoin }: Object
{managers.map((user, n) => (
<UserAvatar
key={n}
name={user.name}
username={user.username}
picture={user.pictureUrl}
size="large"
Expand All @@ -320,6 +324,7 @@ export function TeamSideBar({ team, members, managers, requestedToJoin }: Object
{members.map((user, n) => (
<UserAvatar
key={n}
name={user.name}
username={user.username}
picture={user.pictureUrl}
colorClasses="white bg-blue-grey mv1"
Expand Down
Loading