Skip to content
This repository
  • 5 commits
  • 13 files changed
  • 0 comments
  • 3 contributors
24  app/assets/stylesheets/sections/tree.scss
@@ -52,14 +52,26 @@
52 52
     }
53 53
   }
54 54
 
55  
-  .tree-commit-link {
56  
-    color:#333;
  55
+  .tree_author {
  56
+    padding-right: 8px;
  57
+
  58
+    img.avatar {
  59
+      border: 0 none;
  60
+      float: none;
  61
+      margin-right: 0;
  62
+      padding: 0;
  63
+      width: 16px;
  64
+    }
57 65
   }
58 66
 
59  
-  a.tree-commit-link {
60  
-    color: #666;
61  
-    &:hover {
62  
-      text-decoration: underline;
  67
+  .tree_commit {
  68
+    color: gray;
  69
+
  70
+    .tree-commit-link {
  71
+      color: #444;
  72
+      &:hover {
  73
+        text-decoration: underline;
  74
+      }
63 75
     }
64 76
   }
65 77
 }
8  app/controllers/tree_controller.rb
@@ -48,5 +48,13 @@ def edit_requirements
48 48
     unless @tree.is_blob? && @tree.text?
49 49
       redirect_to project_tree_path(@project, @id), notice: "You can only edit text files"
50 50
     end
  51
+
  52
+    allowed = if project.protected_branch? @ref
  53
+                can?(current_user, :push_code_to_protected_branches, project)
  54
+              else
  55
+                can?(current_user, :push_code, project)
  56
+              end
  57
+
  58
+    return access_denied! unless allowed
51 59
   end
52 60
 end
22  app/decorators/commit_decorator.rb
@@ -42,6 +42,28 @@ def description
42 42
     end
43 43
   end
44 44
 
  45
+  # Returns a link to the commit author. If the author has a matching user and
  46
+  # is a member of the current @project it will link to the team member page.
  47
+  # Otherwise it will link to the author email as specified in the commit.
  48
+  #
  49
+  # options:
  50
+  #  avatar: true   will prepend avatar image
  51
+  def author_link(options)
  52
+    text = if options[:avatar]
  53
+            avatar = h.image_tag h.gravatar_icon(author_email), class: "avatar", width: 16
  54
+            "#{avatar} #{author_name}"
  55
+          else
  56
+            author_name
  57
+          end
  58
+    team_member = @project.try(:team_member_by_name_or_email, author_name, author_email)
  59
+
  60
+    if team_member.nil?
  61
+      h.mail_to author_email, text.html_safe, class: "commit-author-link"
  62
+    else
  63
+      h.link_to text, h.project_team_member_path(@project, team_member), class: "commit-author-link"
  64
+    end
  65
+  end
  66
+
45 67
   protected
46 68
 
47 69
   def no_commit_message
8  app/helpers/tree_helper.rb
@@ -59,4 +59,12 @@ def plain_text_readme? filename
59 59
   def tree_join(*args)
60 60
     File.join(*args)
61 61
   end
  62
+
  63
+  def allowed_tree_edit?
  64
+    if @project.protected_branch? @ref
  65
+      can?(current_user, :push_code_to_protected_branches, @project)
  66
+    else
  67
+      can?(current_user, :push_code, @project)
  68
+    end
  69
+  end
62 70
 end
7  app/models/ability.rb
@@ -35,10 +35,15 @@ def project_abilities(user, project)
35 35
       ] if project.report_access_for?(user)
36 36
 
37 37
       rules << [
38  
-        :write_wiki
  38
+        :write_wiki,
  39
+        :push_code
39 40
       ] if project.dev_access_for?(user)
40 41
 
41 42
       rules << [
  43
+        :push_code_to_protected_branches
  44
+      ] if project.master_access_for?(user)
  45
+
  46
+      rules << [
42 47
         :modify_issue,
43 48
         :modify_snippet,
44 49
         :modify_merge_request,
2  app/roles/authority.rb
@@ -53,6 +53,6 @@ def dev_access_for?(user)
53 53
   end
54 54
 
55 55
   def master_access_for?(user)
56  
-    !users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty? || owner_id == user.id
  56
+    !users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty?
57 57
   end
58 58
 end
5  app/roles/repository.rb
@@ -181,4 +181,9 @@ def ssh_url_to_repo
181 181
   def http_url_to_repo
182 182
     http_url = [Gitlab.config.url, "/", path, ".git"].join('')
183 183
   end
  184
+
  185
+  # Check if current branch name is marked as protected in the system
  186
+  def protected_branch? branch_name
  187
+    protected_branches.map(&:name).include?(branch_name)
  188
+  end
184 189
 end
6  app/roles/team.rb
... ...
@@ -1,7 +1,7 @@
1 1
 module Team
2  
-  def team_member_by_name_or_email(email = nil, name = nil)
3  
-    user = users.where("email like ? or name like ?", email, name).first
4  
-    users_projects.find_by_user_id(user.id) if user
  2
+  def team_member_by_name_or_email(name = nil, email = nil)
  3
+    user = users.where("name like ? or email like ?", name, email).first
  4
+    users_projects.where(user: user) if user
5 5
   end
6 6
 
7 7
   # Get Team Member record by user id
7  app/views/refs/logs_tree.js.haml
... ...
@@ -1,9 +1,8 @@
1 1
 - @logs.each do |content_data| 
2 2
   - file_name = content_data[:file_name]
3  
-  - content_commit = content_data[:commit]
4  
-  - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name)
  3
+  - commit = content_data[:commit]
5 4
 
6 5
   :plain
7 6
     var row = $("table.table_#{@hex_path} tr.file_#{hexdigest(file_name)}");
8  
-    row.find("td.tree_time_ago").html('#{escape_javascript(time_ago_in_words(content_commit.committed_date))} ago');
9  
-    row.find("td.tree_commit").html('#{escape_javascript(render("tree/tree_commit", tm: tm, content_commit: content_commit))}');
  7
+    row.find("td.tree_time_ago").html('#{escape_javascript time_ago_in_words(commit.committed_date)} ago');
  8
+    row.find("td.tree_commit").html('#{escape_javascript render("tree/tree_commit_column", commit: commit)}');
2  app/views/tree/_blob_actions.html.haml
... ...
@@ -1,7 +1,7 @@
1 1
 .btn-group.tree-btn-group
2 2
   -# only show edit link for text files
3 3
   - if @tree.text?
4  
-    = link_to "edit", edit_project_tree_path(@project, @id), class: "btn very_small"
  4
+    = link_to "edit", edit_project_tree_path(@project, @id), class: "btn very_small", disabled: !allowed_tree_edit?
5 5
   = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank"
6 6
   -# only show normal/blame view links for text files
7 7
   - if @tree.text?
3  app/views/tree/_tree_commit.html.haml
... ...
@@ -1,3 +0,0 @@
1  
-- if tm
2  
-  = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm)
3  
-= link_to_gfm truncate(content_commit.title, length: tm ? 30 : 50), project_commit_path(@project, content_commit.id), class: "tree-commit-link"
2  app/views/tree/_tree_commit_column.html.haml
... ...
@@ -0,0 +1,2 @@
  1
+%span.tree_author= commit.author_link avatar: true
  2
+= link_to_gfm truncate(commit.title, length: 80), project_commit_path(@project, commit.id), class: "tree-commit-link"
42  lib/gitlab/backend/grack_auth.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module Grack
2 2
   class Auth < Rack::Auth::Basic
  3
+    attr_accessor :user, :project
3 4
 
4 5
     def valid?
5 6
       # Authentication with username and password
6 7
       email, password = @auth.credentials
7  
-      user = User.find_by_email(email)
  8
+      self.user = User.find_by_email(email)
8 9
       return false unless user.try(:valid_password?, password)
9 10
 
10 11
       # Set GL_USER env variable
@@ -18,28 +19,39 @@ def valid?
18 19
 
19 20
       # Find project by PATH_INFO from env
20 21
       if m = /^\/([\w-]+).git/.match(@request.path_info).to_a
21  
-        return false unless project = Project.find_by_path(m.last)
  22
+        self.project = Project.find_by_path(m.last)
  23
+        return false unless project
22 24
       end
23 25
 
24 26
       # Git upload and receive
25 27
       if @request.get?
26  
-        true
  28
+        validate_get_request
27 29
       elsif @request.post?
28  
-        if @request.path_info.end_with?('git-upload-pack')
29  
-          return project.dev_access_for?(user)
30  
-        elsif @request.path_info.end_with?('git-receive-pack')
31  
-          if project.protected_branches.map(&:name).include?(current_ref)
32  
-            project.master_access_for?(user)
33  
-          else
34  
-            project.dev_access_for?(user)
35  
-          end
36  
-        else
37  
-          false
38  
-        end
  30
+        validate_post_request
39 31
       else
40 32
         false
41 33
       end
42  
-    end# valid?
  34
+    end
  35
+
  36
+    def validate_get_request
  37
+      true
  38
+    end
  39
+
  40
+    def validate_post_request
  41
+      if @request.path_info.end_with?('git-upload-pack')
  42
+        can?(user, :push_code, project)
  43
+      elsif @request.path_info.end_with?('git-receive-pack')
  44
+        action = if project.protected_branch?(current_ref)
  45
+                   :push_code_to_protected_branches
  46
+                 else
  47
+                   :push_code
  48
+                 end
  49
+
  50
+        can?(user, action, project)
  51
+      else
  52
+        false
  53
+      end
  54
+    end
43 55
 
44 56
     def current_ref
45 57
       if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/

No commit comments for this range

Something went wrong with that request. Please try again.