Chris@16: module Checkout Chris@16: class < 0 Chris@16: end Chris@16: Chris@16: def command Chris@16: @command || self.repository && self.repository.checkout_default_command || "" Chris@16: end Chris@16: Chris@16: def append_path? Chris@16: @append_path.to_i > 0 Chris@16: end Chris@16: Chris@16: def access_rw(user) Chris@16: # reduces the three available access levels 'read+write', 'read-only' and 'permission' Chris@16: # to 'read+write' and 'read-only' and nil (not allowed) Chris@16: Chris@16: @access_rw ||= {} Chris@16: return @access_rw[user] if @access_rw.key? user Chris@16: @access_rw[user] = case access Chris@16: when 'permission' Chris@16: case Chris@16: when user.allowed_to?(:commit_access, repository.project) && user.allowed_to?(:browse_repository, repository.project) Chris@16: 'read+write' Chris@16: when user.allowed_to?(:browse_repository, repository.project) Chris@16: 'read-only' Chris@16: else Chris@16: nil Chris@16: end Chris@16: else Chris@16: @access Chris@16: end Chris@16: end Chris@16: Chris@16: def access_label(user) Chris@16: case access_rw(user) chris@1135: when 'read+write' chris@1135: :label_access_read_write chris@1135: when 'read-only' chris@1135: :label_access_read_only Chris@16: end Chris@16: end Chris@16: Chris@16: def fixed_url Chris@16: @fixed_url.present? ? @fixed_url : begin Chris@16: if (regex.blank? || regex_replacement.blank?) Chris@16: repository.url Chris@16: else Chris@16: repository.url.gsub(Regexp.new(regex), regex_replacement) Chris@16: end Chris@16: end Chris@16: rescue RegexpError Chris@16: repository.url || "" Chris@16: end Chris@16: Chris@16: def url(path = "") Chris@16: return "" unless repository Chris@16: Chris@16: url = fixed_url.sub(/\/+$/, "") Chris@16: if repository.allow_subtree_checkout? && self.append_path? && path.present? Chris@16: url = "#{url}/#{path}" Chris@16: end Chris@16: Chris@16: if repository.checkout_display_login? Chris@16: begin Chris@16: uri = URI.parse url Chris@16: (uri.user = repository.login) if repository.login Chris@16: (uri.password = repository.password) if (repository.checkout_display_login == 'password' && repository.login && repository.password) Chris@16: url = uri.to_s Chris@16: rescue URI::InvalidURIError Chris@16: end Chris@16: end Chris@16: url Chris@16: end Chris@16: end chris@1135: end