REFACTOR: Remove mattermost references
This commit is contained in:
parent
60ad4fb3a7
commit
b7bfb6cbea
|
@ -2,9 +2,5 @@ plugins:
|
||||||
discourse_simple_calendar_enabled:
|
discourse_simple_calendar_enabled:
|
||||||
default: true
|
default: true
|
||||||
client: true
|
client: true
|
||||||
discourse_simple_calendar_mattermost_server:
|
|
||||||
default: ""
|
|
||||||
discourse_simple_calendar_mattermost_api_key:
|
|
||||||
default: ""
|
|
||||||
discourse_simple_calendar_holiday_post_id:
|
discourse_simple_calendar_holiday_post_id:
|
||||||
default: ""
|
default: ""
|
||||||
|
|
|
@ -37,48 +37,6 @@ module Jobs
|
||||||
UserCustomField.where(name: ::DiscourseSimpleCalendar::HOLIDAY_CUSTOM_FIELD).where.not(user_id: user_ids).destroy_all
|
UserCustomField.where(name: ::DiscourseSimpleCalendar::HOLIDAY_CUSTOM_FIELD).where.not(user_id: user_ids).destroy_all
|
||||||
|
|
||||||
# puts "Users on holiday are #{users_on_holiday}"
|
# puts "Users on holiday are #{users_on_holiday}"
|
||||||
|
|
||||||
api_key = SiteSetting.discourse_simple_calendar_mattermost_api_key
|
|
||||||
server = SiteSetting.discourse_simple_calendar_mattermost_server
|
|
||||||
|
|
||||||
return if api_key.blank? || server.blank?
|
|
||||||
|
|
||||||
# Fetch all mattermost users
|
|
||||||
response = Excon.get("#{server}/api/v4/users", headers: {
|
|
||||||
"Authorization": "Bearer #{api_key}"
|
|
||||||
})
|
|
||||||
mattermost_users = JSON.parse(response.body, symbolize_names: true)
|
|
||||||
|
|
||||||
# Loop over mattermost users
|
|
||||||
mattermost_users.each do |user|
|
|
||||||
mattermost_username = user[:username]
|
|
||||||
marked_on_holiday = !!mattermost_username.chomp!("-v")
|
|
||||||
|
|
||||||
discourse_user = User.find_by_email(user[:email])
|
|
||||||
next unless discourse_user
|
|
||||||
discourse_username = discourse_user.username
|
|
||||||
|
|
||||||
on_holiday = users_on_holiday.include?(discourse_username)
|
|
||||||
|
|
||||||
update_username = false
|
|
||||||
if on_holiday && !marked_on_holiday
|
|
||||||
update_username = "#{mattermost_username}-v"
|
|
||||||
elsif !on_holiday && marked_on_holiday
|
|
||||||
update_username = mattermost_username
|
|
||||||
end
|
|
||||||
|
|
||||||
if update_username
|
|
||||||
# puts "Update #{mattermost_username} to #{update_username}"
|
|
||||||
Excon.put("#{server}/api/v4/users/#{user[:id]}/patch", headers: {
|
|
||||||
"Authorization": "Bearer #{api_key}"
|
|
||||||
}, body: {
|
|
||||||
username: update_username
|
|
||||||
}.to_json)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue