diff --git a/app/models/data_exception.rb b/app/models/data_exception.rb new file mode 100644 index 000000000..70e03b524 --- /dev/null +++ b/app/models/data_exception.rb @@ -0,0 +1,3 @@ +class DataException < ActiveRecord::Base + attr_accessible :container_id, :container_type, :message +end diff --git a/db/migrate/20161213074134_create_data_exceptions.rb b/db/migrate/20161213074134_create_data_exceptions.rb new file mode 100644 index 000000000..a9f79402c --- /dev/null +++ b/db/migrate/20161213074134_create_data_exceptions.rb @@ -0,0 +1,11 @@ +class CreateDataExceptions < ActiveRecord::Migration + def change + create_table :data_exceptions do |t| + t.string :message + t.integer :container_id + t.string :container_type + + t.timestamps + end + end +end diff --git a/lib/tasks/gitlab_sync.rake b/lib/tasks/gitlab_sync.rake new file mode 100644 index 000000000..d4ff704c0 --- /dev/null +++ b/lib/tasks/gitlab_sync.rake @@ -0,0 +1,35 @@ +namespace :gitlab do + desc "make sure trustie'data consistent with gitlab's data" + task :sync_date => :environment do + projects = Project.where("gpid is not null") + s = Trustie::Gitlab::Sync.new + g = Gitlab.client + begin + projects = Project.where(:status => 1) + projects.each do |project| + # sync members and roles + if project.members.count != g.team_members(project.gpid).count + DataException.create(:message => "project's members is not true", :container_id => project.id, :container_type => "Project") + s.only_members(project) + end + end + + users = User.where("gpid is not null and status =?", 1) + users.each do |user| + # sync username + g.edit_user(user.gid, :username => user.login) if user.login != g.user(user.gid).try(:username) + + # sync email + g.edit_user(user.gid, :email => user.mail) if user.mail != g.user(user.gid).try(:email) + + # sync password + options = {:encrypted_password=> user.hashed_password, :password_salt=> user.salt} + g.put("/users/ext/#{uid}", :body => options) + end + rescue Exception => e + DataException.create(:message => e.message) + puts e + end + + end +end diff --git a/spec/models/data_exception_spec.rb b/spec/models/data_exception_spec.rb new file mode 100644 index 000000000..566563cbb --- /dev/null +++ b/spec/models/data_exception_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DataException, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end