2017-06-04 18:42:43 +00:00
|
|
|
module EmacsCollab
|
|
|
|
class Project
|
2017-06-15 00:20:13 +00:00
|
|
|
attr_accessor :uid, :id, :path, :posixname, :users, :owner
|
2017-06-04 18:42:43 +00:00
|
|
|
attr_reader :keys
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@users = []
|
2017-06-15 00:20:13 +00:00
|
|
|
@keys = []
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{@id}, #{@path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_key(key)
|
|
|
|
@keys << key
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_user(user)
|
|
|
|
@users << user
|
2017-06-15 00:20:13 +00:00
|
|
|
# TODO: Remove the following comments
|
|
|
|
#user.keys.each do |key|
|
|
|
|
# add_key(key)
|
|
|
|
#end
|
2017-06-04 18:42:43 +00:00
|
|
|
flush
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_user(user)
|
|
|
|
@user.delete(user)
|
2017-06-15 00:20:13 +00:00
|
|
|
# TODO Make sure to remove the key of the user
|
2017-06-04 18:42:43 +00:00
|
|
|
flush
|
|
|
|
refresh
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh
|
2017-06-15 00:20:13 +00:00
|
|
|
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def flush
|
2017-06-15 00:20:13 +00:00
|
|
|
$db.update_project(self)
|
|
|
|
|
|
|
|
EmacsCollab.get_ssh_keyfile(self,"w+") do |key_file|
|
2017-06-04 18:42:43 +00:00
|
|
|
@users.each do |user|
|
2017-06-15 00:20:13 +00:00
|
|
|
EmacsCollab.get_user_by_id(user).keys.each do |key|
|
2017-06-04 18:42:43 +00:00
|
|
|
key_file << "#{key.to_s}\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class DuplicateProjectError < StandardError
|
|
|
|
end
|
|
|
|
|
2017-06-15 00:20:13 +00:00
|
|
|
class ProjectNotFoundError < StandardError
|
|
|
|
end
|
|
|
|
|
2017-06-04 18:42:43 +00:00
|
|
|
end
|