summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <morris.jobke@gmail.com>2014-03-13 13:20:00 +0100
committerMorris Jobke <morris.jobke@gmail.com>2014-03-13 13:20:00 +0100
commit3c03ff5bb554b0b738864f857d18e35762f13d18 (patch)
treee183139ce90546b1b8161a73d0c9b84e922b25e8
parent9fa9c791eb09013e38ebe0d7739ab862eae611ce (diff)
parent8fafee31efd9cb8126cc82017b6bb2d614d9b977 (diff)
downloadnextcloud-server-3c03ff5bb554b0b738864f857d18e35762f13d18.tar.gz
nextcloud-server-3c03ff5bb554b0b738864f857d18e35762f13d18.zip
Merge pull request #7340 from owncloud/hide_remove_image_avatar
Hide remove image, if there's no custom avatar
-rw-r--r--settings/js/personal.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/settings/js/personal.js b/settings/js/personal.js
index 7a4257f1c97..f502037cfda 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -60,6 +60,8 @@ function updateAvatar (hidedefault) {
}
$displaydiv.css({'background-color': ''});
$displaydiv.avatar(OC.currentUser, 128, true);
+
+ $('#removeavatar').show();
}
function showAvatarCropper() {
@@ -256,6 +258,7 @@ $(document).ready(function(){
url: OC.generateUrl('/avatar/'),
success: function(msg) {
updateAvatar(true);
+ $('#removeavatar').hide();
}
});
});
@@ -278,6 +281,18 @@ $(document).ready(function(){
t('core', 'Strong password')
]
});
+
+ // does the user have a custom avatar? if he does hide #removeavatar
+ // needs to be this complicated because we can't check yet if an avatar has been loaded, because it's async
+ var url = OC.generateUrl(
+ '/avatar/{user}/{size}',
+ {user: OC.currentUser, size: 1}
+ ) + '?requesttoken=' + oc_requesttoken;
+ $.get(url, function(result) {
+ if (typeof(result) === 'object') {
+ $('#removeavatar').hide();
+ }
+ });
} );
OC.Encryption = {
ghlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?php
declare (strict_types = 1);
/**
 * @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu>
 *
 * @author Michael Weimann <mail@michael-weimann.eu>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace Tests\Core\Controller;

use OC\AppFramework\Http;
use OC\Core\Controller\SvgController;
use OC\Template\IconsCacher;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
use Test\TestCase;

/**
 * This class provides test cases for the svg controller
 */
class SvgControllerTest extends TestCase {

	const TEST_IMAGES_SOURCE_PATH = __DIR__ . '/../../data/svg';
	const TEST_IMAGES_PATH = __DIR__ . '/../../../core/img/testImages';
	const TEST_IMAGE_MIXED = 'mixed-source.svg';
	const TEST_IMAGE_RECT = 'rect-black.svg';
	const TEST_IMAGES = [
		self::TEST_IMAGE_MIXED,
		self::TEST_IMAGE_RECT,
	];

	/**
	 * @var SvgController
	 */
	private $svgController;

	/**
	 * Copy test svgs into the core img "test" directory.
	 *
	 * @beforeClass
	 * @return void
	 */
	public static function copyTestImagesIntoPlace() {
		mkdir(self::TEST_IMAGES_PATH);
		foreach (self::TEST_IMAGES as $testImage) {
			copy(
				self::TEST_IMAGES_SOURCE_PATH .'/' . $testImage,
				self::TEST_IMAGES_PATH . '/' . $testImage
			);
		}
	}

	/**
	 * Removes the test svgs from the core img "test" directory.
	 *
	 * @afterClass
	 * @return void
	 */
	public static function removeTestImages() {
		foreach (self::TEST_IMAGES as $testImage) {
			unlink(self::TEST_IMAGES_PATH . '/' . $testImage);
		}
		rmdir(self::TEST_IMAGES_PATH);
	}

	/**
	 * Setups a SVG controller instance for tests.
	 *
	 * @before
	 * @return void
	 */
	public function setupSvgController() {
		$request = $this->getMockBuilder(IRequest::class)->getMock();
		$timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
		$appManager = $this->getMockBuilder(IAppManager::class)->getMock();
		$iconsCacher = $this->getMockBuilder(IconsCacher::class)->disableOriginalConstructor()->setMethods(['__construct'])->getMock();
		$this->svgController = new SvgController('core', $request, $timeFactory, $appManager, $iconsCacher);
	}

	/**
	 * Checks that requesting an unknown image results in a 404.
	 *
	 * @test
	 * @return void
	 */
	public function testGetSvgFromCoreNotFound() {
		$response = $this->svgController->getSvgFromCore('huhuu', '2342', '#ff0000');
		self::assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
	}

	/**
	 * Provides svg coloring test data.
	 *
	 * @return array
	 */
	public function provideGetSvgFromCoreTestData(): array {
		return [
			'mixed' => ['mixed-source', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/mixed-red.svg')],
			'black rect' => ['rect-black', 'f00', file_get_contents(self::TEST_IMAGES_SOURCE_PATH . '/rect-red.svg')],
		];
	}

	/**
	 * Tests that retrieving a colored SVG works.
	 *
	 * @test
	 * @dataProvider provideGetSvgFromCoreTestData
	 * @param string $name The requested svg name
	 * @param string $color The requested color
	 * @param string $expected The expected svg
	 * @return void
	 */
	public function testGetSvgFromCore(string $name, string $color, string $expected) {
		$response = $this->svgController->getSvgFromCore('testImages', $name, $color);

		self::assertEquals(Http::STATUS_OK, $response->getStatus());

		$headers = $response->getHeaders();
		self::assertArrayHasKey('Content-Type', $headers);
		self::assertEquals($headers['Content-Type'], 'image/svg+xml');

		self::assertEquals($expected, $response->getData());
	}
}