Find the list of inactive users in Bitbucket?

巧了我就是萌 提交于 2021-02-08 08:32:13

问题


How can I find the list of those users who never logged in to their Bitbucket account? Is there any query or macro, or will I have to do it manually ?


回答1:


You can do this with SQL query to database:

    SELECT cu.lower_user_name
      ,cu.display_name
      ,cu.lower_display_name
      ,cu.lower_email_address
      ,cu.is_active
      ,dateadd(second,cast(cast(cua.attribute_value AS nvarchar(255)) AS bigint)/1000,'19700101 00:00:00:000') AS LAST_LOGIN
  FROM [BitBucketDB].[dbo].[cwd_user] As cu
      LEFT JOIN [BitBucketDB].[dbo].cwd_membership AS cm
        ON cu.directory_id=cm.directory_id
        AND cu.lower_user_name=cm.lower_child_name
        AND cm.membership_type='GROUP_USER'

      LEFT JOIN [BitBucketDB].[dbo].cwd_user_attribute As cua
      ON cu.ID = cua.user_id and cua.attribute_name='lastAuthenticationTimestamp' 
      WHERE cm.lower_parent_name='stash-users' 



回答2:


See also the Atlassian KB on the topic: https://confluence.atlassian.com/bitbucketserverkb/query-for-inactive-or-idle-users-779171719.html In essence, Bitbucket Server (and Data Center):

  • shows Last authenticated column in the list of users (under Administration > Users)
  • offers REST API to query the last authenticated date for any given user



回答3:


Here is a solution for Postgresql, notice that you may want to consider the creation date of a user to exclude those that got their access yesterday and did not mange to login yet.

Users who have not logged in for one year or never, but who exist for at least one year:

select * from (SELECT distinct cu.lower_user_name
      ,to_timestamp(CAST(attribute_value AS BIGINT)/1000) AS last_login
      ,cu.created_date
FROM cwd_user As cu
      LEFT JOIN cwd_membership AS cm
        ON cu.directory_id=cm.directory_id
        AND cu.lower_user_name=cm.lower_child_name
        AND cm.membership_type='GROUP_USER'

      LEFT JOIN cwd_user_attribute As cua
          ON cu.ID = cua.user_id and
          cua.attribute_name='lastAuthenticationTimestamp'
      WHERE is_active = 'T'AND (cm.lower_parent_name='stash-users' OR
          cm.lower_parent_name='bitbucket-users'
      OR cm.lower_parent_name='stash' OR
          cm.lower_parent_name='bitbucket') ) q1
      where  (last_login < current_date - (365) or last_login is null)
      and created_date < current_date - (365);


来源:https://stackoverflow.com/questions/47648296/find-the-list-of-inactive-users-in-bitbucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!