Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
ce527b68
Commit
ce527b68
authored
Dec 24, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'improve/avatar_upload_only_images' of /home/git/repositories/gitlab/gitlabhq
parents
ede3446c
62f1c977
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
app/models/user.rb
app/models/user.rb
+7
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+14
-0
No files found.
app/models/user.rb
View file @
ce527b68
...
@@ -113,9 +113,8 @@ class User < ActiveRecord::Base
...
@@ -113,9 +113,8 @@ class User < ActiveRecord::Base
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
}
message:
"only letters, digits & '_' '-' '.' allowed. Letter should be first"
}
validates
:notification_level
,
inclusion:
{
in:
Notification
.
notification_levels
},
presence:
true
validates
:notification_level
,
inclusion:
{
in:
Notification
.
notification_levels
},
presence:
true
validate
:namespace_uniq
,
if:
->
(
user
)
{
user
.
username_changed?
}
validate
:namespace_uniq
,
if:
->
(
user
)
{
user
.
username_changed?
}
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar_changed?
}
validates
:avatar
,
file_size:
{
maximum:
100
.
kilobytes
.
to_i
}
validates
:avatar
,
file_size:
{
maximum:
100
.
kilobytes
.
to_i
}
before_validation
:generate_password
,
on: :create
before_validation
:generate_password
,
on: :create
...
@@ -244,6 +243,12 @@ class User < ActiveRecord::Base
...
@@ -244,6 +243,12 @@ class User < ActiveRecord::Base
end
end
end
end
def
avatar_type
unless
self
.
avatar
.
image?
self
.
errors
.
add
:avatar
,
"only images allowed"
end
end
# Groups user has access to
# Groups user has access to
def
authorized_groups
def
authorized_groups
@authorized_groups
||=
begin
@authorized_groups
||=
begin
...
...
spec/models/user_spec.rb
View file @
ce527b68
...
@@ -279,4 +279,18 @@ describe User do
...
@@ -279,4 +279,18 @@ describe User do
User
.
by_username_or_id
(
'bar'
).
should
be_nil
User
.
by_username_or_id
(
'bar'
).
should
be_nil
end
end
end
end
describe
:avatar_type
do
let
(
:user
)
{
create
(
:user
)
}
it
"should be true if avatar is image"
do
user
.
update_attribute
(
:avatar
,
'uploads/avatar.png'
)
user
.
avatar_type
.
should
be_true
end
it
"should be false if avatar is html page"
do
user
.
update_attribute
(
:avatar
,
'uploads/avatar.html'
)
user
.
avatar_type
.
should
==
[
"only images allowed"
]
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment