Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a global config option root_user that can delete users and accounts

Add a global config option to allow signups so they can be turned off
and only the admin can create new users.
  • Loading branch information...
commit 1e8433e617c9bae276aaef9bf2f883b581ba7272 1 parent 5a90694
@icefox authored
View
1  web/app/controllers/repositories_controller.rb
@@ -251,6 +251,7 @@ def find_repository
def requires_authorization
return if !find_repository
+ return true if @loggedinuser.username == GitHavenConfig["root_user"]
if @owner != @loggedinuser
@repository = nil
flash[:notice] = t('repository.notowner')
View
22 web/app/controllers/users_controller.rb
@@ -49,6 +49,14 @@ def show
# GET /users/new
def new
+ if GitHavenConfig["allow_signup"] == false && !(@loggedinuser and @loggedinuser.username == GitHavenConfig["root_user"])
+ flash[:notice] = t('user.nosignups')
+ respond_to do |format|
+ format.html { redirect_to(root_url) }
+ format.xml { head :ok }
+ end
+ return
+ end
@user = User.new
respond_to do |format|
@@ -104,8 +112,20 @@ def update
# DELETE /users/1
def destroy
+ @user = @loggedinuser
username = @loggedinuser.username
- @loggedinuser.destroy
+
+ if username == GitHavenConfig["root_user"]
+ @user = User.find(params[:id]) if params[:id]
+ username = @user.username
+ end
+
+ if username == GitHavenConfig["root_user"]
+ flash[:notice] = t('user.deletedroot', :username => username)
+ redirect_to(root_url)
+ end
+
+ @user.destroy
flash[:notice] = t('user.deleted', :username => username)
respond_to do |format|
format.html { redirect_to(root_url) }
View
7 web/app/models/repository.rb
@@ -22,13 +22,18 @@ def initialize(arg=nil)
permissions << permission
end
+ def admin(user)
+ return true if user && self.user == user
+ return user.username == GitHavenConfig["root_user"]
+ end
+
def authorized(user)
return true if user && self.user == user
permissions.each { |p|
return true if user && p.user_id == user.id
return true if p.user.username == I18n.t('user.all')
}
- return false
+ return (user and user.username == GitHavenConfig["root_user"])
end
def location
View
2  web/app/views/repositories/_repositorytopbar.html.erb
@@ -38,6 +38,6 @@
<% @repository.links.each { |l| %>
<li><a target="_blank" href="<%= l.url %>"><%= l.name %></a>
<% } %>
- <% if @owner == @loggedinuser -%><li id="repository_admin"><%= link_to 'Admin', edit_repository_path(@repository) %></li><% end %>
+ <% if @repository.admin(@loggedinuser) -%><li id="repository_admin"><%= link_to 'Admin', edit_repository_path(@repository) %></li><% end %>
</ul>
</div>
View
3  web/app/views/users/index.html.erb
@@ -18,6 +18,9 @@
<td><%=h user.url %></td>
<td><%=h user.avatar %></td>
<td><%= link_to 'Show', user %></td>
+<% if @loggedinuser and GitHavenConfig["root_user"] == @loggedinuser.username and user.username != I18n.t('user.all') -%>
+ <td><%= link_to 'Delete', user, :method => :delete %></td>
+<% end -%>
</tr>
<% end %>
</table>
View
9 web/config/githaven.yml
@@ -1,5 +1,14 @@
production:
+ # Message shown at the top of every web page
system_message: "Welcome to GitHaven, see /var/git/githaven/config/githaven.conf for custom server configuration."
+ # When this is set to false only the root_user can create new accounts
+ allow_signup: true
+
+ # This user can do anything, create accounts, delete users, repositories etc
+ root_user:
+
development:
system_message:
+ allow_signup: true
+ root_user:
View
2  web/config/locales/en.yml
@@ -12,10 +12,12 @@ en:
password: "Password"
loggedout: "Logged out"
accessdenied: "This action requires that you be logged in"
+ nosignups: "Only the admin is allowed to create new users"
invalid_user_or_password: "Invalid username or password"
created: "User successfully created: {{username}}"
updated: "User successfully updated: {{username}}"
deleted: "User successfully deleted: {{username}}"
+ deletedroot: "Not allowed to delete the root user"
sshkey:
notsshkey: "must begin with ssh-rsa or ssh-dss"
nosshkeyhint: "Note: to push to a repository you need to add a ssh key."
Please sign in to comment.
Something went wrong with that request. Please try again.