Class: GitContacts::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gitcontacts/Request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id) ⇒ Request

Returns a new instance of Request.



28
29
30
# File 'lib/gitcontacts/Request.rb', line 28

def initialize request_id
  @obj =  RequestObject::access request_id
end

Class Method Details

.create(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gitcontacts/Request.rb', line 10

def create hash
  # all keys are required
  obj = RequestObject.new
  obj.uid = hash[:uid]
  obj.gid = hash[:gid]
  obj.time = Time.now.to_i
  obj.card_id = hash[:card_id] if hash.member? :card_id
  obj.action = hash[:action]
  obj.content = hash[:content] if hash.member? :content
  obj.request_id
end

.delete(request_id) ⇒ Object



22
23
24
# File 'lib/gitcontacts/Request.rb', line 22

def delete request_id
  return true if RequestObject::delete(request_id) > 0
end

.exist?(request_id) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/gitcontacts/Request.rb', line 6

def exist? request_id
  return true if RequestObject::exist?(request_id)
end

Instance Method Details

#allow(operator) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/gitcontacts/Request.rb', line 70

def allow operator
  author = User.new getuid
  operator = User.new operator
  contacts = Gitdb::Contacts.new(getuid).access getgid
  card = Gitdb::Card.new contacts.repo
  
  case getaction
  when 'create'
    card.create getuid 
  when 'setmeta'
    card.access(getcard_id).setmeta JSON.parse(getcontent, { symbolize_names: true })
  when 'setdata'
    card.access(getcard_id).setdata JSON.parse(getcontent, { symbolize_names: true })
  when 'delete'
    card.access(getcard_id).delete
  end
  
  commit_obj = {
    :author => { :name => author.getuid, :email => author.getemail, :time => Time.at(get_req_time.to_i) },
    :committer => { :name => operator.getuid, :email => operator.getemail, :time => Time.now }
  }

  contacts.make_a_commit commit_obj
  card.getmeta[:id]
end

#auto_merge?(uid) ⇒ Boolean

code review: @AustinChou

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitcontacts/Request.rb', line 57

def auto_merge? uid
  if contacts = Contacts.new(getgid)
    if contacts.getadmins.include? uid
      return true
    else
      case getaction
      when "setdata" ,"delete"
        return true if Gitdb::Card.new(getgid).access(getcard_id).getmeta[:owner] == getuid # to-do
      end
    end
  end
end

#denyObject



96
97
98
99
100
101
# File 'lib/gitcontacts/Request.rb', line 96

def deny
  # deny merge here
  author = User.new getuid
  author.remove_request @obj.request_id
  Request::delete @obj.request_id
end

#get_req_timeObject



48
49
50
# File 'lib/gitcontacts/Request.rb', line 48

def get_req_time
  @obj.time.value if @obj
end

#getactionObject



40
41
42
# File 'lib/gitcontacts/Request.rb', line 40

def getaction
  @obj.action.value if @obj
end

#getcard_idObject



44
45
46
# File 'lib/gitcontacts/Request.rb', line 44

def getcard_id
  @obj.card_id.value if @obj
end

#getcontentObject



52
53
54
# File 'lib/gitcontacts/Request.rb', line 52

def getcontent
  @obj.content.value if @obj
end

#getgidObject



36
37
38
# File 'lib/gitcontacts/Request.rb', line 36

def getgid
  @obj.gid.value if @obj
end

#getuidObject



32
33
34
# File 'lib/gitcontacts/Request.rb', line 32

def getuid
  @obj.uid.value if @obj
end