Skip to content

Commit

Permalink
Show surveys count in users list (#3606)
Browse files Browse the repository at this point in the history
* Users list: added count of owned surveys

* layout adjustments

* user access request: associate survey to user being invited

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 679b4cb commit 13a7de8
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/i18n/resources/en/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ Copy the invitation link to the clipboard?`,
label: 'Survey extra property',
label_other: 'Survey extra properties',
},
surveysDraft: 'Surveys (draft)',
surveysPublished: 'Surveys (published)',
},

usersAccessRequestView: {
Expand Down
2 changes: 2 additions & 0 deletions core/survey/_survey/surveyInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export const assocSrs = (srs) => ObjectUtils.setProp(keys.srs, srs)

export const assocRDBInitilized = R.assoc(keys.rdbInitialized)

export const assocOwnerUuid = R.assoc(keys.ownerUuid)

// ====== UTILS

export const isValid = (surveyInfo) => !!surveyInfo?.id
Expand Down
3 changes: 2 additions & 1 deletion core/survey/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export const {
export const { getAuthGroupByName, getAuthGroups, isAuthGroupAdmin, getAuthGroupAdmin } = SurveyInfo

// UPDATE
export const { assocAuthGroups, assocFilesStatistics, assocRDBInitilized, assocSrs, markDraft } = SurveyInfo
export const { assocAuthGroups, assocFilesStatistics, assocOwnerUuid, assocRDBInitilized, assocSrs, markDraft } =
SurveyInfo

// ====== READ nodeDefs
export const {
Expand Down
4 changes: 4 additions & 0 deletions core/user/_user/userKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export const keys = {
// Used only when editing user auth groups
authGroupsUuids: 'authGroupsUuids',
authGroupExtraProps: 'authGroupExtraProps',

// Used only in list view
surveysCountDraft: 'surveysCountDraft',
surveysCountPublished: 'surveysCountPublished',
}
2 changes: 2 additions & 0 deletions core/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const getAuthGroupsUuids = R.propOr([], keys.authGroupsUuids)
export const getAuthGroupExtraProps = R.propOr({}, keys.authGroupExtraProps)
export const getAuthGroupExtraProp = (prop) => R.pipe(getAuthGroupExtraProps, R.prop(prop))
export const getLastLoginTime = R.prop(keys.lastLoginTime)
export const getSurveysCountDraft = R.prop(keys.surveysCountDraft)
export const getSurveysCountPublished = R.prop(keys.surveysCountPublished)

// ====== UPDATE
export const assocProp = R.assoc
Expand Down
14 changes: 13 additions & 1 deletion server/modules/user/repository/userRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,19 @@ const _usersSelectQuery = ({
SELECT uar.props ->> '${UserAccessRequest.keysProps.country}'
FROM user_access_request uar
WHERE uar.email = u.email
) AS country
) AS country,
(
SELECT COUNT(*)
FROM survey s
WHERE s.owner_uuid = u.uuid
AND s.published
) AS surveys_count_published,
(
SELECT COUNT(*)
FROM survey s
WHERE s.owner_uuid = u.uuid
AND NOT s.published
) AS surveys_count_draft
FROM "user" u
${includeSurveys ? `LEFT JOIN user_surveys ON user_surveys.user_uuid = u.uuid` : ''}
LEFT OUTER JOIN us
Expand Down
8 changes: 6 additions & 2 deletions server/modules/user/service/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const acceptUserAccessRequest = async ({ user, serverUrl, accessRequestAc
languages: ['en'],
})

const survey = await _insertOrCloneSurvey({ user, surveyInfoTarget, templateUuid }, t)
let survey = await _insertOrCloneSurvey({ user, surveyInfoTarget, templateUuid }, t)

// 3) find group to associate to the user
let group = null
Expand All @@ -222,16 +222,20 @@ export const acceptUserAccessRequest = async ({ user, serverUrl, accessRequestAc
}

// 4) invite user to that group and send email
const surveyId = Survey.getId(survey)
const { userInvited } = await UserInviteService.inviteUsers(
{
user,
surveyId: Survey.getId(survey),
surveyId,
surveyCycleKey: Survey.cycleOneKey,
invitation: UserGroupInvitation.newUserGroupInvitation(email, AuthGroup.getUuid(group)),
serverUrl,
},
t
)
const surveyOwnerUuid = User.getUuid(userInvited)
await SurveyManager.updateSurveyOwner({ user, surveyId, ownerUuid: surveyOwnerUuid, system: true })
survey = Survey.assocOwnerUuid(surveyOwnerUuid)(survey)
return { survey, userInvited }
})

Expand Down
1 change: 1 addition & 0 deletions webapp/views/App/views/Users/UsersList/UsersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const UsersList = () => {
rowExpandedComponent={({ item }) => <UserSurveysTable user={item} />}
headerLeftComponent={TableHeaderLeft}
selectable={false}
visibleColumnsSelectionEnabled
/>
)
}
14 changes: 14 additions & 0 deletions webapp/views/App/views/Users/UsersList/useUsersListColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ export const useUsersListColumns = () => {
<ButtonIconEdit disabled={!User.hasAccepted(item)} onClick={() => goToUserDetails(item)} />
),
},
{
key: User.keys.surveysCountDraft,
header: 'usersView.surveysDraft',
hidden: true,
renderItem: ({ item }) => User.getSurveysCountDraft(item),
width: '10rem',
},
{
key: User.keys.surveysCountPublished,
header: 'usersView.surveysPublished',
hidden: true,
renderItem: ({ item }) => User.getSurveysCountPublished(item),
width: '12rem',
},
],
[goToUserDetails, i18n]
)
Expand Down

0 comments on commit 13a7de8

Please sign in to comment.