user creation using sql query

Neha Pande December 6, 2017

For a given list of projects, find the roles in that project, who the users are in that role, including who the groups are in that role

looking for SQL query for this.

2 answers

0 votes
Neha Pande December 7, 2017

Hi Micky,

Thank you for the solution But i tried the same in sql server its not working. moreover I don't want to restrict the role as only admins. 

 

I tried the below query but I dnt think its giving the right result If u can suggest anything on this.

select cwd_group.group_name, cwd_user.user_name, cwd_user.display_name, cwd_user.email_address,
(select attribute_value from cwd_user_attribute where cwd_user_attribute.user_id = cwd_user.id and cwd_user_attribute.attribute_name = "lastAuthenticated") as lastAuthenticated from cwd_membership left join cwd_user on cwd_user.id = cwd_membership.child_user_id left join cwd_group on cwd_membership.parent_id = cwd_group.id order by user_name asc;

0 votes
miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2017

Hi Neha,

If you want to read from DB that's OK and you should look at the cwd_membership table which holds relationships between users and groups. Regarding the project roles, the table is projectroleactor (associating roles with actors of type user or group) and projectrole which is the list of available project roles.

here is a query I've used to extract project with their admins. The projectroleid filter can be removed/updated to suit your needs:

SELECT p.id AS 'PID',
pkey AS 'Key',
p.pname 'Name',
ISNULL(u.display_name,'') AS 'Lead',
ISNULL((SELECT COUNT(*) FROM jiraissue GROUP BY project HAVING project = p.ID),0) AS 'Issues',
p.projecttype AS 'Type',
ISNULL((SELECT cname FROM projectcategory WHERE id = (SELECT sink_node_id FROM nodeassociation WHERE source_node_id = p.id AND association_type='ProjectCategory')),'') AS 'Category',
LEFT((
SELECT CONCAT(roletypeparameter, ' (',REPLACE(REPLACE(roletype,'atlassian-',''),'-role-actor',''),')')+', ' AS "text()"
FROM projectroleactor
WHERE pid = p.id AND projectroleid = 10002 AND roletypeparameter <> 'jira-administrators'
FOR XML PATH('')
),255) AS 'Admins'
FROM project p
LEFT JOIN app_user au ON au.user_key = p.lead
LEFT JOIN cwd_user u ON u.lower_user_name = au.lower_user_name

Please note that the query is designed for SQL Server and might be adapted for your database server.

Hope this helps!

Cheers 

Neha Pande December 7, 2017

Hi Micky,

Thank you for the solution But i tried the same in sql server its not working. moreover I don't want to restrict the role as only admins. 

 

I tried the below query but I dnt think its giving the right result If u can suggest anything on this.

select cwd_group.group_name, cwd_user.user_name, cwd_user.display_name, cwd_user.email_address,
(select attribute_value from cwd_user_attribute where cwd_user_attribute.user_id = cwd_user.id and cwd_user_attribute.attribute_name = "lastAuthenticated") as lastAuthenticated from cwd_membership left join cwd_user on cwd_user.id = cwd_membership.child_user_id left join cwd_group on cwd_membership.parent_id = cwd_group.id order by user_name asc;

Neha Pande

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events